Python Forum

Full Version: I have a Toplevel button in tkinker that I want to close the window and then perform
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So far I have created a frame with some functioning buttons/menus. One of my menu buttons opens a new Toplevel window. This new Toplevel window is basically a forum fill out page. At the end of the page is a done button. This done button closes the tkiniter Toplevel window while leaving the root window. I wish to execute lines of code after the button is pressed.
My first idea was to set the done button command to make the window 'withdrawn'. If I do this, it does withdraw the window but if I try to run an if check the check will already have been checked before the button is pressed. The most simple solution to this would be to create a function the withdraws the window and does the other stuff I am wanting, however, when I try to pass a function as the command for the Toplevel done button it does not call the function.
Any advice how to make the button close the window and then perform additional code (Only after the button is pressed) would be greatly appreciated. I have attached the section of code in question below. Thank You in advance for your help. (Side note Computer class is handled in another file). (I am using Python 3.x)

def draw_new_computer_entry(self):
   t = Toplevel(self)
   t.resizable(0,0)
   t.wm_title("Solution Center: Add New Computer")
   t.geometry("300x300")
   nameLabel = Label(t, text="Computer Name:")
   nameLabel.place(x=0,y=10)

   a = computer()

   comp_nameEntry = Entry(t, width=30)
   comp_nameEntry.place(master=None, x=100, y=10)
   a.name = comp_nameEntry.get()

   comp_makerEntry= Entry(t,width=30)
   comp_makerEntry.place(x=100, y=50)
   a.maker = comp_makerEntry.get()

   makerLabel= Label(t, text="Maker:")
   makerLabel.place(x=55,y=50)

   graphics_cardEntry= Entry(t, width=30)
   graphics_cardEntry.place(x=100,y=90)
   a.gpu = graphics_cardEntry.get()

   graphics_cardLabel= Label(t, text="Graphics Card:")
   graphics_cardLabel.place(x=15, y=90)

   processorEntry= Entry(t, width=30)
   processorEntry.place(x=100, y=130)
   a.processor = processorEntry.get()

   processorLabel= Label(t, text="Processor:")
   processorLabel.place(x=38, y=130)

   hard_driveEntry= Entry(t, width=30)
   hard_driveEntry.place(x=100, y=170)
   a.hard_drive = hard_driveEntry.get()

   hard_driveLabel= Label(t, text="Hard Drive:")
   hard_driveLabel.place(x=30, y=170)

   ramEntry= Entry(t, width=30)
   ramEntry.place(x=100, y=210)

   ramLabel= Label(t,text="Ram:")
   ramLabel.place(x=65,y=210)
   doneButton = Button(t, text="done", command=t.withdraw)
   doneButton.place(x=265, y=275)
(Jan-06-2017, 06:17 PM)Bloodypizza17 Wrote: [ -> ]when I try to pass a function as the command for the Toplevel done button it does not call the function.
Give an example of this
Welp, it seems that I am just a noob lol. When I was trying to pass the command as a function I forget to put self.function. Sorry