Python Forum
[Tkinter] I have a Toplevel button in tkinker that I want to close the window and then perform
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] I have a Toplevel button in tkinker that I want to close the window and then perform
#1
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)
Reply


Messages In This Thread
I have a Toplevel button in tkinker that I want to close the window and then perform - by Bloodypizza17 - Jan-06-2017, 06:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 529 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  pass a variable between tkinter and toplevel windows janeik 10 2,365 Jan-24-2024, 06:44 AM
Last Post: Liliana
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,861 May-25-2023, 07:37 PM
Last Post: deanhystad
  [PyQt] command require close window Krissstian 14 2,974 Nov-19-2022, 04:18 PM
Last Post: Krissstian
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,920 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Toplevel window menator01 5 3,076 Apr-18-2022, 06:01 PM
Last Post: menator01
  [Tkinter] Clicking on the button crashes the TK window ODOshmockenberg 1 2,252 Mar-10-2022, 05:18 PM
Last Post: deanhystad
  [Tkinter] Not able to get image as background in a Toplevel window finndude 4 3,927 Jan-07-2022, 10:10 PM
Last Post: finndude
  [Tkinter] Images in Toplevel() finndude 4 4,310 Mar-09-2021, 09:39 AM
Last Post: finndude
Question closing a "nested" window with a button in PySimpleGUI and repeating this process Robby_PY 9 13,614 Jan-18-2021, 10:21 PM
Last Post: Serafim

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020