Tkinter question

Eric Brunel eric.brunel at pragmadev.com
Mon Oct 21 04:02:00 EDT 2002


dsavitsk wrote:

> Every now and again I get it in my head that some new project would be
> best
> done in Tkinter.  Every time I find myself struggling horribly.  I have
> the
> Grayson book, I have a Fredrik Lundh pdf book from '99.  Somewhere,
> something doesn't click. So, along with the specific questions, I am also
> looking for a Tkinter moment of clarity.
> 
> Currently, I am trying to put together a project with a base window, and
> one
> dialog.  The base window is for most work, but the dialog pops up for
> certain editing of parameters, etc. The parts which I am having trouble
> with are (a) making the dialog modal (only one can exist, and the root
> window can't be reached until the dialog is closed), and (b) I would like
> to return
> data from the dialog to the root window.  Neither of these seem like they
> should be terribly difficult, yet they elude me.
[snip code]

First of all, if I understood correctly, there's no "standard" way with 
tk/Tkinter to make a window modal in itself; it's the caller that decides 
if the window should be modal or not.

So here is the way I do things whenever I want to make a modal window:

dlg = MyDialogClass(...)   # Always a sub-class of Toplevel
dlg.grab_set()
dlg.transient(rootWdw)
rootWdw.wait_window(dlg)

What prevents the root window to be reactive is the "transient" stuff. The 
explanation of this method can be found in the tk man pages @ 
http://www.tcl.tk/man/tcl8.3/TkCmd/contents.html (the site appears to be 
broken for now, so I can't tell you the actual entry).

HTH
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com



More information about the Python-list mailing list