Tk's default Toplevel - counterintuitive
Stuart Reynolds
S.I.Reynolds at cs.bham.ac.uk
Thu Aug 19 16:55:09 EDT 1999
Does anyone know how to tell if Tk has already instaniated a Toplevel
window? I want to be able to open several Toplevel windows in any order.
Something like:
def makeNewWindow():
if defaulttoplevel in use:
mstr=Toplevel
else:
mstr=None #Uses the default Toplevel
f = Frame(master=mstr)
...
Cheers,
Stuart
PS. Wouldn't it have made more sense if using None as a window's master
caused a new Toplevel window to be created rather than the situation now
where you end up sticking items all in the same window. The following
gives 1 window containing 3 buttons (doh!):
---
from Tkinter import *
def makeNewWindow():
f = Frame(master=None)
b=Button(master=f, text="Hello")
b.pack(side=LEFT, fill=BOTH)
Pack.config(f)
makeNewWindow()
makeNewWindow()
makeNewWindow()
---
A naive alternative is:
---
def makeNewWindow():
f = Frame( master=Toplevel() )
...as before
----
Which gives you three separate windows but a random extra empty Toplevel
window (the mystery default `None' toplevel)... DohDoh!
More information about the Python-list
mailing list