Movatterモバイル変換
[0]ホーム
Tkinter Toplevel spawned in event handler
Alexander Slusarczykaslusarc at pc46.ics.ele.tue.nl
Fri Apr 27 09:11:34 EDT 2001
Hi!I am a Tkinter rookie, so please bear with me if I'm doingsomething obviously stupid.I am trying to write a simple Tkinter application, which will show modeless windows with some content as the reaction to button press.I am trying to achieve it with the following code:----class MyWin(Toplevel): def __init__(self,master,number): Toplevel.__init__(self,master) self.number = number Label( self , text=str(self.number) ).pack() self.bind("<Escape>", self.cancel) self.wait_window(self) def cancel(self,event=None): print "Canceling",self.number self.destroy() def new_window(): global win_number, root no = win_number win_number = win_number + 1 print "Showing",no t = MyWin(root,no) print "Canceled",noroot=Tk()win_number=0Button(root, text="New Window",command=new_window).pack()root.mainloop()----when I run it and create 3 windows (0,1 and 2), and then "<Escape>" themin the order of their creation I get the following:Showing 0Showing 1Showing 2Canceling 0Canceling 1Canceling 2Canceled 2Canceled 1Canceled 0it seems that MyWin(root,x) for a window only returns, after the MyWin() forall the windows created AFTER x have returned (?!)Am I making any sense? Does anyone have an explanation, or - preferably - a fix ?Thanks in advance,Alex
More information about the Python-listmailing list
[8]ページ先頭