[Tkinter-discuss] Open a Help window from a Dialog window
Vasilis Vlachoudis
Vasilis.Vlachoudis at cern.ch
Wed Sep 19 14:28:45 CEST 2007
Dear all,
in my application I would like to have a "Help" button in every dialog
that opens the common help window. The problem is that the Dialog window
has the "grab_set" activated so when I open the help window, all the
events are still redirected to the Dialog. The Help window appears on
screen but is inactive. Is there a way to specify that the Help window
is for example a separate thread and still handles the events in
parallel of the Dialog which has the grab_set for the rest of the program?
Below you can find an example on what I am trying to do, if the user
first clicks on the "Dialog" button and then from the dialog window
clicks on "Help" the Help window is frozen.
from Tkinter import *
class Help:
def __init__(self, master):
self.toplevel = Toplevel(master)
frame = Frame(self.toplevel, bg="Yellow")
frame.pack(expand=YES, fill=BOTH)
t = Label(frame, text="The quick brown fox jumps\nover the lazy
dogs tail")
t.pack()
b = Button(frame, text="Quit", padx=50, command=self.quit)
b.pack()
self.toplevel.title("Help")
self.toplevel.protocol("WM_DELETE_WINDOW", self.quit)
def show(self):
self.toplevel.wait_visibility()
def quit(self, event=None):
self.toplevel.destroy()
class Dialog:
def __init__(self, master):
self.toplevel = Toplevel(master)
frame = Frame(self.toplevel, bg="Blue")
frame.pack(expand=YES, fill=BOTH)
b = Button(frame, text="Help", padx=50, command=self.help)
b.pack()
b = Button(frame, text="Quit", padx=50, command=self.quit)
b.pack()
self.toplevel.title("Dialog")
self.toplevel.protocol("WM_DELETE_WINDOW", self.quit)
def show(self):
self.toplevel.grab_set()
self.toplevel.wait_window()
def quit(self, event=None):
self.toplevel.destroy()
def help(self, event=None):
help = Help(root)
help.show()
def dialog():
dlg = Dialog(root)
dlg.show()
def help():
win = Help(root)
win.show()
def quit():
root.destroy()
# -----
root = Tk()
root.title("Root")
Button(root, text="Dialog", padx=50, command=dialog).pack()
Button(root, text="Help", padx=50, command=help).pack()
Button(root, text="Quit", padx=50, command=quit).pack()
root.mainloop()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Vasilis.Vlachoudis.vcf
Type: text/x-vcard
Size: 312 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20070919/da3f7ed6/attachment.vcf
More information about the Tkinter-discuss
mailing list