get data from a Toplevel when closing it
polux
polux2001 at wanadoo.fr
Sun Nov 3 07:58:50 EST 2002
first, excuse my english...I'm french
I made a class derivated from the Tkinter's Toplevel class like this :
Myclass(Toplevel):
def __init__(self,master,**arg)
Toplevel.__init__(master,arg)
self.master = master
Now, I want to get data from this Toplevel (eg data from entries
widgets) when I'm closing it.
I've found a trick in the Filedialog.py example file which consists in
creating a fonction like this :
def go(self):
self.master.mainloop
return data
and an other activated by a 'quit' button for example :
def quit(self):
data = self.entry.get()
self.master.destroy()
self.master.quit()
I'm launching my class like this :
root = Tk()
m = Myclass(root)
data = m.go()
root.mainloop()
root.destroy()
It works but they are two problems :
1. It seems to be a 'dirty' method to do this
2. when I'am exiting the root window ( by clicking on a button for
example), I have to do it twice because there are 2 mainloop() launched
Please help me if there is a better way to do it....I'm sure there is.
More information about the Python-list
mailing list