windows

Peter Abel PeterAbel at gmx.net
Wed Oct 13 13:22:14 EDT 2004


Ajay <abra9823 at mail.usyd.edu.au> wrote in message news:<mailman.4811.1097649067.5135.python-list at python.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).
But here is a hackaround:

import Tkinter

#----------------------
def deiconify(widget):
#----------------------
  widget.deiconify()
  widget.grab_set()

#----------------------
def withdraw(widget):
#----------------------
  widget.grab_release()
  widget.withdraw()

# The root window
root=Tkinter.Tk()

# The Toplevel window
tl=Tkinter.Toplevel(root,width=400,height=200,bg='white')

# Withdraw Toplevel, when destroyed
tl.protocol("WM_DELETE_WINDOW",lambda w=tl:withdraw(w))

# Make Toplevel not resizable
tl.resizable(width=False,height=False)

# Default state of Toplevel is withdrawn
tl.withdraw()

# Give Toplevel window a title
tl.title('Toplevel-Window')

# A Button on the root window to make Toplevel window visible
Tkinter.Button(root,text='Toplevel on',command=lambda w=tl:deiconify(w)).pack()

# Start mainloop
root.mainloop()

Regards
Peter



More information about the Python-list mailing list