|
|
|||
Chained/Nested Modal windows in Python tkinter
I'm creating a python application (I'm using 3.1.3) that will have a gui built using tkinter. I'm trying to get multiple modal windows that should be chained together ie The first window is inoperable until the second window is closed and the second window is inoperable until the third is closed. The behavior seems to be ok when the three windows are on screen. The problem is that when I close the third window, the first becomes responsive again, and no longer waits for the second. I am almost certain that there are some events bubbling up somewhere causing this (had this problem before), but I am not sure how to fix this. I have attached a very simple stripped down version of how my application does this (it seems the site is screwing up my indentation - there is no problem there). By pressing the slave button on the first window, a second is opened and pressing its slave creates a third. These should be chained like I described above.
from tkinter import * num=1 class ModalWindow(Toplevel): def __init__(self,parent=None,message="",*args1,**args2): Toplevel.__init__(self,parent,*args1,**args2) Label(self,text=message).pack() def makeModal(parent): global num win=ModalWindow(parent,"Slave "+str(num)) num+=1 Button(win,text="Slave",command=(lambda self=win: makeModal(self))).pack() win.focus_set() win.grab_set() parent.wait_window(win) root=Tk() Label(root,text="Root Window").pack() Button(root,text="Slave",command=(lambda self=root: makeModal(self))).pack() root.mainloop() 0 Replies |
|||
|