I am currently working on my first serious GUI application in python using Tkinter. I currently have a toplevel window that opens from the root window. when i envoke the window from the root i can see all 7 of my other widgets, but the widget:

btncancel = Tkinter.Button(addboard, text = "Cancel", command = addboard.destroy)
btncancel.grid(row = 4, column = 1)

does not appear in my toplevel window (addboard). However when i click where the button is supposed to be it appears under my cursor while mouse is clicked and it properly executes addboard.destroy
how do i fix this problem?
(also how do i properly wrap my code in the (code) as this is my first post with a code snippet

(also how do i properly wrap my code in the [code] as this is my first post with a code snippet

[CODE]#First line of code
.
.
.
.
#Last line of code[/CODE]

That should've worked. I don't know why it wouldn't.

Try adding changing background colour see if it shows up then.

btncancel = Tkinter.Button(addboard, text = "Cancel", command = addboard.destroy, bg = "red")

Another way of doing it is next time you post some code, highlight all of said code and hit the code button on the posting options.

If my suggestion doesnt give you any results then post more of your code, you might be having problems elsewhere.

The following is the two buttons that are to be in my window (addboard):

btnok = Tkinter.Button(addboard, text = "Continue", command = tah)
    btnok.grid(row= 5, column = 3)
    btncancel = Tkinter.Button(addboard, text = "Cancel", command = addboard.destroy, bg= 'red')
    btncancel.grid(row = 5, column = 1)

when btnok and btn cancel are switched around so that:

btncancel = Tkinter.Button(addboard, text = "Cancel", command = addboard.destroy, bg= 'red')
    btncancel.grid(row = 5, column = 1)
    btnok = Tkinter.Button(addboard, text = "Continue", command = tah)
    btnok.grid(row= 5, column = 3)

i get the same problem but with the btnok button

My complete Toplevel is as follows:

def addmovie():
    addboard = Tkinter.Toplevel()
    addboard.title("Add a movie")
    addboard.geometry("600x600")
    #addboard(padx=10, pady=10)
    print "add"
    #adding the title
    
    lbtitle = Tkinter.Label(addboard, text = "Enter the movie's title:")
    lbtitle.grid(row = 1, column = 1)
    entitle = Tkinter.Entry(addboard)
    entitle.grid(row = 1, column = 3)
    #adding the director
    lbdirector = Tkinter.Label(addboard, text = "Enter the mmovie's director:")
    lbdirector.grid(row = 2, column = 1)
    endirector = Tkinter.Entry(addboard)
    endirector.grid(row = 2, column = 3)
    #adding the year
    lbyear = Tkinter.Label(addboard, text = "Enter the movie's year:")
    lbyear.grid(row = 3, column = 1)
    enyear = Tkinter.Entry(addboard)
    enyear.grid(row = 3, column = 3)
    #if a value is left blank program will ask what to do
    #to be added later
    
    #The button and the commands to put it all together
    btnok = Tkinter.Button(addboard, text = "Continue", command = tah)
    btnok.grid(row= 5, column = 4)
    btncancel = Tkinter.Button(addboard, text = "Cancel", command = addboard.destroy, bg= 'red')
    btncancel.grid(row = 5, column = 1)

The following slightly modified code displays correctly for me on a Slackware Linux system.

import Tkinter

def addmovie(root):
    addboard = Tkinter.Toplevel()
    addboard.title("Add a movie")
    addboard.geometry("600x600")
    #addboard(padx=10, pady=10)
    print "add"
    #adding the title
 
    lbtitle = Tkinter.Label(addboard, text = "Enter the movie's title:")
    lbtitle.grid(row = 1, column = 1)
    entitle = Tkinter.Entry(addboard)
    entitle.grid(row = 1, column = 3)
    #adding the director
    lbdirector = Tkinter.Label(addboard, text = "Enter the mmovie's director:")
    lbdirector.grid(row = 2, column = 1)
    endirector = Tkinter.Entry(addboard)
    endirector.grid(row = 2, column = 3)
    #adding the year
    lbyear = Tkinter.Label(addboard, text = "Enter the movie's year:")
    lbyear.grid(row = 3, column = 1)
    enyear = Tkinter.Entry(addboard)
    enyear.grid(row = 3, column = 3)
    #if a value is left blank program will ask what to do
    #to be added later
 
    #The button and the commands to put it all together
    btnok = Tkinter.Button(addboard, text = "Continue")
    btnok.grid(row= 5, column = 4)
    btncancel = Tkinter.Button(addboard, text = "Cancel", bg= 'red', command=root.quit)
    btncancel.grid(row = 5, column = 1)


root = Tkinter.Tk()
addmovie(root)
root.mainloop()

the code works much thanks for the help. what have i left out between my code and yours? is there something i had left out?

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.