Peter Abel wrote:
Ajay <ab******@mail.usyd.edu.au> wrote in message news:<ma**************************************@pyt hon.org>...
hi!
i have two tkinter windows on top of each other. i would like it so that
the user has to complete the fields in the top windows before they can
interact with the window below it. that is, i dont want the user to close
the top window or minimize it or send it into the background.
how would i do it?
thanks
cheers
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
There are documentations which say that Tkinter.Toplevel has
a methode .transient(root) which should make the Toplevel window
transient to its root window.
But I never managed to make it work.(W2K Python 2.2.2).
Read tk commands manual:
"""
wm transient window ?master?
If master is specified, then the window manager is informed that window is
a transient window (e.g. pull-down menu) working on behalf of master (where
master is the path name for a top-level window). Some window managers will use
this information to manage window specially.
"""
Nothing is said about which window should have the grab. And in fact, Windows
actually does something when a window is made transient; try this in an
interactive Python session:
from Tkinter import *
root = Tk()
wdw = Toplevel()
wdw.transient(root)
You can first notice that the minimize and maximize buttons have disappeared
from the secondary window's title bar, and that the close button has shrinked a
little. Then, if you try to put the main window above the secondary one, you'll
see that you can't. But you can still make the main window active.
So transient is only part of the solution. You also want to set the grab on the
secondary window, and then wait for the secondary window to close. Here is an
example doing that:
--modal.py-------------------------------------------------
from Tkinter import *
root = Tk()
def go():
wdw = Toplevel()
Entry(wdw).pack()
wdw.transient(root)
wdw.grab_set()
root.wait_window(wdw)
print 'done!'
Button(root, text='Go', command=go).pack()
Button(root, text='Quit', command=root.quit).pack()
root.mainloop()
-----------------------------------------------------------
So this is the magical sequence to make a window modal in Tkinter: transient,
grab_set, wait_window.
[snip]
HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools -
http://www.pragmadev.com