here is a solution :

from Tkinter import *
root = Tk()
def callback():
    print 'clicked on cross'
class App:
  def __init__(self, master):
        c = Button(master, text="Only one")
    c.bind("<Button-1>", lambda e, s=self:s.cb(master))
        c.pack()

  def cb(self,master):#, event):
        win = Toplevel(master)
        win.protocol('WM_DELETE_WINDOW',callback)
    win.title("one")
    frame= Frame(win)
        b=Button(frame, text='ok', command=win.quit)
    b.pack()
        frame.pack()
app=App(root)
root.mainloop()


Olivier



V H wrote:

>Hi all,
>
>I use a button  to generate a toplevel window. I hope only one such window 
>is existing before I close it manually. But now each time when I click the 
>button a new window is created. How can I do?
>
>How do I bind a function to the close of the window by clicking the cross in 
>the up-right side?
>
>Following is a example program. You solution or suggetstiong is very 
>appreciated .
>
>regards,
>Vning
>
>
>
>from Tkinter import *
>root = Tk()
>class App:
>  def __init__(self, master):
>        c = Button(master, text="Only one")
>       c.bind("<Button-1>", lambda e, s=self:s.cb(master))
>        c.pack()
>  def cb(self,master):#, event):
>        win = Toplevel(master)
>       win.title("one")
>       frame= Frame(win)
>        b=Button(frame, text='ok', command=win.quit)
>       b.pack()
>        frame.pack()
>app=App(root)
>root.mainloop()
>
>_________________________________________________________________
>Don't just search. Find. Check out the new MSN Search! 
>http://search.msn.com/
>
>_______________________________________________
>Tkinter-discuss mailing list
>[email protected]
>http://mail.python.org/mailman/listinfo/tkinter-discuss
>
>  
>


_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to