hi,
im currently making a food ordering system in python. I recently decided to put a background in the window and now all of my buttons have disappeared?? does anyone know why this might be.

function[]=panel(alpha)

chord=5;
V=100;


[x,y]=shapegenerator(0,chord);
[xm,ym]=controlpoints(x,y);
p=size(xm);


%plot(xm,ym)
N=p(2);
sum = 0;
for i = 1:N
sum = sum+ ((x(i+1) - x(i))^2+(y(i+1)-y(i))^2)^.5;
end

i'm kinda new to this so could you possibly dumb it down for me?

here is my code if you want to test it

from Tkinter import *
import Tkinter as tk



def create_header(t,top):
  ## Creates the Headings
    frame1 = Frame(top, relief=GROOVE, borderwidth=2)
    label1 = Label(frame1, text=t, font=('Arial', sqsize/2), fg="red")
    label1.pack()
    top.create_window(middle, sqsize, window=frame1, anchor=N)
    top.pack(fill='both', expand='yes')

def create_buttons(t,place,c, top):
    ## Creates the Buttons
    frame2 = Frame(top, relief=GROOVE, borderwidth=2)
    button1 = Button(frame2, text=t, command=c, font=('Arial', middle/16), fg="blue")
    button1.pack(side="left")
    top.create_window(middle, place, window=frame2, anchor=N)
    top.pack(fill='both', expand='yes')

def create_top(frame):
    top = Canvas(frame, bg='white', width=s, height=s)
    # pick a .gif image file you have in the working directory
    
    # creates the background
    image1 = tk.PhotoImage(file="foodimage.gif")
    w = image1.width()
    h = image1.height()
    panel1 = tk.Label(root, image=image1)
    panel1.pack(side='top', fill='both', expand='yes')      
    panel1.image = image1   
    return top

def create_text(t,top):
    frame3 = Frame(top, relief=GROOVE, borderwidth=2)
    label2 = Label(frame3, text=t, font=('Arial', middle/16), fg="black")
    label2.pack()
    top.create_window(middle, sqsize*2, window=frame3, anchor=N)
    top.pack(fill='both', expand='yes')

def action():
    pass

def create_main():
    frame = Frame(None, borderwidth=2)
    top=create_top(frame)
    top.pack()

    create_header('Food Ordering System', top)

    for t,place,c in (('Help', 3*sqsize, go_help),
                    ('Register as Member', 4*sqsize, go_register),
                    ('Order Food', 5*sqsize, go_food_menu),
                    ('Quit', 7*sqsize, root.destroy),
                    ):
        create_buttons(t,place,c,top)

    return frame

def create_menu():
    ## create here all widgets under frame, which is not active (parent None)
    frame = Frame(None, borderwidth=2)
    top=create_top(frame)
    
    for t,place,c in (('Food Menu', 3*sqsize, go_menu),
                    ('Chefs Specials', 4*sqsize, go_help_text),
                    ('Main menu', 7*sqsize, go_main),
                    ):
        create_buttons(t,place,c,top)
    
    return frame ## return created frame through which can access its widgets

def create_register():
    frame = Frame(None, borderwidth=2)
    top=create_top(frame)
    create_header('Register',top)

    for t,place,c in (('Submit', 6*sqsize, go_register),
                    ('Main menu', 7*sqsize, go_main),
                    ):
        create_buttons(t,place,c,top)

    return  frame

def create_food_ordering_system():
    frame = Frame(None, borderwidth=2)
    top=create_top(frame)
    create_header('Todays Specials',top)
    create_text("""Todays specials are as follows
                """,top) #use """ to get space.

    for t,place,c in (('Back', 6*sqsize, go_help),
                      ('Main menu', 7*sqsize, go_main),
                      ):
        create_buttons(t,place,c,top)

    return frame

def create_about():
    frame = Frame(None, borderwidth=2)
    top=create_top(frame)
    create_header('About',top)

    for t,place,c in (('Back', 6*sqsize, go_about),
                      ('Main menu', 7*sqsize, go_main),
                      ):
        create_buttons(t,place,c,top)

    return frame

def create_register_sucessful():
    frame = Frame(None, borderwidth=2)
    top=create_top(frame)
    create_text(""" Congradulations Your Registration
        has been sucessful""",top)

    for t,place,c in (('Back', 6*sqsize, go_register_sucessful),
                      ('Main menu', 7*sqsize, go_main),
                      ):
        create_buttons(t,place,c,top)

    return frame

def create_food_menu():
    frame = Frame(None, borderwidth=2)
    top=create_top(frame)
    create_header('Menu',top)

    for t,place,c in (('Back', 6*sqsize, go_help),
                      ('Main menu', 7*sqsize, go_main),
                      ):
        create_buttons(t,place,c,top)

    return frame

def create_help():

    frame = Frame(None, borderwidth=2)
    top=create_top(frame)
    create_header('Help',top)
    
    for t,place,c in (('About', 3*sqsize, go_help),
                        ('How do I Register?', 5*sqsize, action),
                        ('Main menu', 7*sqsize, go_main),
                      ## comma makes easier later to put more things here
                      ):
            create_buttons(t,place,c, top)
                      
    return  frame  ## must not pack the returned frame

def go_help():
    global currentframe
    currentframe.pack_forget() ## forget the old currentframe
    currentframe=helpframe ## put prepared gameframe instaid
    currentframe.pack(fill='both', expand='yes') ## pack it to become visible

def go_register():
    global currentframe
    currentframe.pack_forget()
    currentframe=registerframe
    currentframe.pack(fill='both', expand='yes')

def go_menu():
    global currentframe
    currentframe.pack_forget()
    currentframe=menuframe
    currentframe.pack(fill='both', expand='yes')

def go_main():
    global currentframe
    currentframe.pack_forget()
    currentframe=mainframe
    currentframe.pack(fill='both', expand='yes')

def go_help_text():
    global currentframe
    currentframe.pack_forget()
    currentframe=helptext
    currentframe.pack(fill='both', expand='yes')

def go_about():
    global currentframe
    currentframe.pack_forget()
    currentframe=abouttext
    currentframe.pack(fill='both', expand='yes')

def go_register_sucessful():
    global currentframe
    currentframe.pack_forget()
    currentframe=register_sucess_text
    currentframe.pack(fill='both', expand='yes')

def go_food_menu():
    global currentframe
    currentframe.pack_forget()
    currentframe=food_menu_text
    currentframe.pack(fill='both', expand='yes')

def diag_stripe(top,colors,sqsize,cols,rows=None):
    """ top=object to drawin, sqsize=sqsize of the square
        cols,rows = number of cols and rows
    """
    if not rows: rows=cols ## can not put rows=cols in parameter list
    cl=len(colors) 
    col=0
    
    for j in range(0,rows*sqsize,sqsize):
        for i in range (0,cols*sqsize,sqsize):
            fill=colors[col]
            top.create_rectangle(i,j,i+sqsize, j+sqsize,fill=fill)
            col=(col+1)%cl
        if not cols % cl: col=(col+1)%cl


if __name__=="__main__":    
    root = Tk()
    root.title("Food Ordering System ")

    numsq=8
    sqsize=70 
    s=sqsize*numsq 


    middle=numsq/2*sqsize

    root.geometry("%sx%s+%s+%s" % (s,s,0,0))

    root.resizable(width=FALSE, height=FALSE)

    currentframe = mainframe = create_main()
    menuframe = create_menu()
    registerframe = create_register()
    helpframe = create_help()
    helptext = create_food_ordering_system()
    abouttext = create_about()
    register_sucess_text = create_register_sucessful()
    food_menu_text = create_food_menu()

    go_main()

    root.mainloop()

Well, it doesn't even look like deepak's code is Python. I'm not quite sure what is going on with that.

Anyways, I do not see any immediate problems why your code should not work except for the constant calling of the function "create_top." You call it eight times? That would mean you create eight canvases with eight background images? Am I missing something or is that your most apparent problem?

EDIT: If this is actually tyonyjv's code, I will definitely not try to question its methods; his GUI algorithms are above my skill level. He will unquestionably know more about it than I do, so try to ask him politely. Good luck.

That is not your code. That is code I wrote for a base of checkers program in earlier thread, including comments and diag_stripe routine for producing the board. Remember to mention the origin of your code or at least not claim that you wrote it.

You mixed up the order of frames:

def create_top(frame):
    top = Canvas(frame, bg='white', width=s, height=s)
    # pick a .gif image file you have in the working directory
    
    # creates the background
    image1 = tk.PhotoImage(file="foodimage.gif")
    w = image1.width()
    h = image1.height()
    panel1 = tk.Label(top, image=image1) ## top!!!
    panel1.pack(side='top', fill='both', expand='yes')      
    panel1.image = image1   
    return top
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.