python - How to close Toplevel window after the function it calls completes? -
edit: let me include code can specific help.
import tkinter def gopush(): win2=tkinter.toplevel() win2.geometry('400x50') tkinter.label(win2,text="if have prepared describes select go otherwise select go back").pack() tkinter.button(win2,text="go",command=bounceprog).pack(side=tkinter.right,padx=5) tkinter.button(win2, text="go back", command=win2.destroy).pack(side=tkinter.right) def bounceprog(): d=1 print d root=tkinter.tk() root.geometry('500x100') tkinter.button(text='go', command=gopush).pack(side=tkinter.right,ipadx=50) root.mainloop()
so when run program opens window says go. go opens window asks if youve read help(which didnt include in code sample) , offers go back(which goes back) , go. when select go calls function prints 1. after prints 1 want window close returning original window containing go button. how do such thing?
@kosig won't quit root. ie. self.foo = tk.toplevel(self)
, self.foo.destroy()
for example:
class foo(tk.frame): """foo example""" def __init__(self, master=none): """draw foo gui""" tk.frame.__init__(self, master) self.grid() self.draw_window_bar() def draw_window_bar(self): """draw bar toplevel window""" self.window_bar = tk.toplevel(self) # uber-pythonian code here... ask_yes_or_no = messagebox.askyesno('brian?', 'romani ite domum') if not ask_yes_or_no: self.window_bar.destroy()
you have 1 main object, foo. foo has 1 main window (called "frame"), gets tk.frame
. afterwards, toplevel windows (frames) must created within it. so, new window here self.window_bar
, "objects" in there, including method destroying (self.window_bar.destroy()
). can call self.window_bar.destroy()
part of code, here called after user clicks "no".
Comments
Post a Comment