Python window.destroy()?

Jerry 2jerry at writeme.com
Tue Feb 22 19:50:08 EST 2000


here is a correct script ...
enjoy

#!/usr/bin/python
from Tkinter import *

class App:
  def __init__(s,master):
    frame=Frame(master)
    frame.pack()
    s.button1 = Button(frame,text="Button1")
    s.button1.pack(side=LEFT)
    s.button2 = Button(frame,text="Button2")
    s.button2.pack(side=RIGHT)
    # all binds could be create here ... more readable ... or before pack (i
prefer) :-)
    s.button2.bind("<Enter>",s.myEcho2)
    s.button1.bind("<Enter>",s.myEcho1)
    s.button1.bind("<Leave>",s.out1)
    s.button2.bind("<Leave>",s.out2)
    Button(frame,text="QUIT",command=frame.quit).pack(side=LEFT)

  def myEcho1(s,event):
    s.wm1=Toplevel()
    s.wm1.label=Label(s.wm1,text="Mouse is on the 2nd button")
    s.wm1.label.pack()

  def out1(s,event):
    """This function is needed cause s.wm1.destroy is not a valid callback
       a callback via a bind allways send an event object as argument
       this is not the case of a Button for example ...
    """
    s.wm1.destroy()

  def myEcho2(s,event):
    s.wm2=Toplevel()
    s.wm2.label=Label(s.wm2,text="Mouse is on the 1st button")
    s.wm2.label.pack()

  def out2(s,event):
    'see for out1 __doc__'
    s.wm2.destroy()

root=Tk()
app = App(root)
root.mainloop()

ns56645 a écrit dans le message <38B1F028.7A2036C2 at swt.edu>...
>Jerry Thanks for your help,
>
>To give you the complete picture I have send you my program. I need to
>kill  two new windows that were created when I moved my mouse on the
>window.
>
>See to the program and you can get the picture. I am still in the lab
>for
>another hour.
>
>Thanks,
>
>
>#!/usr/bin/python
>
>from Tkinter import *
>
>
>class App:
>
>
>def __init__(self,master):
>
>frame=Frame(master)
>
>frame.pack()
>
>
>self.button1 = Button(frame,text="Button1")
>   self.button1.pack(side=LEFT)
>
>
>self.button2 = Button(frame,text="Button2")
>   self.button2.pack(side=RIGHT)
>
>
>self.Quit= Button(frame,text="QUIT",command=frame.quit)
>   self.Quit.pack(side=LEFT)
>
>
>def myEcho2(event):
>
>wm1=Toplevel()
>
>wm1.label=Label(wm1,text="Mouse is on the 2nd button")
>    wm1.label.pack()
>
>
>def myEcho1(event):
>
>wm2=Toplevel()
>
>wm2.label=Label(wm2,text="Mouse is on the 1st button")
>    wm2.label.pack()
>
>   self.button2.bind("<Enter>",myEcho2)
>
>self.button2.pack()
>
>
>self.button1.bind("<Enter>",myEcho1)
>
>self.button1.pack()
>
>
>self.button2.bind("<Leave>",wm2.destroy)
>
>self.button2.pack()
>
>   self.button1.bind("<Leave>",wm1.destroy)
>   self.button1.pack()
>root=Tk()
>
>app = App(root)
>
>root.mainloop()
>
>
>
>





More information about the Python-list mailing list