Implicit initialization is EVIL!

rantingrick rantingrick at gmail.com
Mon Jul 4 17:19:40 CEST 2011


On Jul 4, 3:33 am, Gregory Ewing <greg.ew... at canterbury.ac.nz> wrote:

> IMO the real problem here is the existence of a privileged
> "root" window at all. No GUI platform I know of has any
> such concept (except for a "desktop" window that represents
> the whole screen, which is not the same thing). All top-level
> windows should have equal status.


I dunno, it's natural to create a parent-child hierarchy when GUI
programming with any library. So i am not completely sure what you are
implying here? When you close the main application widow you would
expect all child windows to close. Or likewise when you iconify the
main window you would expect the other windows to do the same. Sure
you could do this yourself by sending messages to all the other
windows but Tkinter does this for you automatically. And how does
Tkinter know which windows to configure? A parent-child relationship
that's how.

>>> a = set(dir(Tkinter.Toplevel))
>>> b = set(dir(Tkinter.Tk))
>>> len(a), len(b)
(222, 226)
>>> a.difference(b)
set(['_setup', '_do'])

You say "root" windows are bad however any parent-child relationship
has to BEGIN somewhere. For Tkinter the beginning of this dynasty is
an instance of the Tkinter.Tk[1] window from which all other windows
and widgets are made children. HOWEVER any of the windows ARE in fact
instances of Tk.Toplevel[1]. So they ARE all equal because they all
have the same methods available to them.

>>> import Tkinter
>>> Tkinter.Tk.__doc__
'Toplevel widget of Tk which represents mostly the main window\n    of
an appliation. It has an associated Tcl interpreter.'
>>> import inspect
>>> inspect.getmro(Tkinter.Tk)
(<class Tkinter.Tk at 0x02742210>, <class Tkinter.Misc at 0x02742570>,
<class Tkinter.Wm at 0x0272F780>)
>>> inspect.getmro(Tkinter.Toplevel)
(<class Tkinter.Toplevel at 0x02742690>, <class Tkinter.BaseWidget at
0x02742630>, <class Tkinter.Misc at 0x02742570>, <class Tkinter.Wm at
0x0272F780>)

But let's dig a little deeper here. Your comment suggests that you
"personally" need to create multiple windows for your applications. Is
this correct? If so i pity any users of such application as they would
be thoroughly confused. Most applications consist of one main window
(a Tkinter.Tk instance). The only need for extra Toplevel windows is
in the form of modal dialogs (use tkSimpleDialog.Dialog) or tool
windows (use Tk.Toplevel with attribute '-toolwindow'=True).

I don't see how your statements carry any weight here. Could you
explain please?

[1] http://effbot.org/tkinterbook/tkinter-application-windows.htm
[2] http://effbot.org/tkinterbook/toplevel.htm



More information about the Python-list mailing list