Tkinter Dialog Management problems:
eric_brunel at despammed.com
Fri May 19 09:26:37 CEST 2006
On Thu, 18 May 2006 11:52:54 -0400, Michael Yanowitz
<m.yanowitz at kearfott.com> wrote:
> Thanks. That helped alot.
> However it leaves a couple very minor problems which I think I can live
> 1) It brings up an empty additional 'main window'.
> I have tried using the Tkinter.NoDefaultRoot() option, but run into
> other problems with other things not defined.
> NameError: global name '_default_root' is not defined
> Exception exceptions.AttributeError: "IntVar instance has no attribute
> '_tk'" in
> <bound method IntVar.__del__ of <Tkinter.IntVar instance at 0x009C7990>>
> 2) By deriving the 'dialog' from Tk, existing calls to self.pack() no
> longer are valid, but they don't appear to be necessary.
> My only 'Tkinter tutorial' is what is included in Orielly's
> Python". Still looking for a good tutorial. I am not clear what the
> between Tk() and Toplevel() are. They seem totally interchangeable.
No, they're not! Never - and I mean *never* - create two instances of Tk
in the same application! The Tk instance does not only represent the main
window for the application, but also creates the underlying tcl
interpreter. Creating two instances of Tk will then create two
interpreters and you'll never know which one executes your commands,
producing weird TclError's everywhere.
If you have a window which can be considered as the main window for your
application - there is only one of it, it is always there and closing it
means quitting the application -, then make it a sub-class of Tk. If you
do not have such a window, use the following trick at the beginning of
root = Tkinter.Tk()
This basically creates a main window and immediately hides it. All your
other windows must be sub-classes of Toplevel. Calling the quit method of
these windows should still quit the application, and calling the destroy
method should only close the window.
As for tutorials, there are many; just see there:
Apart from the one already given by Rony (which is more a reference than a
tutorial), my favorite ones are:
- Stephen Ferg's "Thinking in Tkinter" -
- The one at http://doctormickey.com/python/index.html
- Gerard Swinnen's "Apprendre a programmer avec Python" (in French) -
At least, these ones avoid the confusion Frame/window usually found in
many others: the first two don't use inheritance at all; only the last
(the one in French) implements windows as sub-classes of Tk or Toplevel.
Unfortunately, I don't know any english translation of it.
A last advice: if you want to do serious Tkinter, it really helps to know
how the underlying tcl/tk layer works. So maybe you should learn at least
the basics of tcl/tk. And if you do that, you will be able to use tcl/tk
resources, such as:
which is the only documentation I ever need now...
python -c "print ''.join([chr(154 - ord(c)) for c in
More information about the Python-list