NEED HELP

Rob Wolfe blue99 at interia.pl
Tue Aug 29 06:47:16 EDT 2006


mailme.grover at gmail.com wrote:
> Below is my code, which is kind of virtual and with its help ill use it
> in my main project.
> Now what i am looking for is can anybody write all the code inside a
> class...so that I can reuse it. I am kind of novice...n kind of stuc
> with that.
>
> from Tkinter import *
>
> root = Tk()
>
> w = Label(root, text="Right-click to display menu", width=40,
> height=20)
> w.pack()
>
> # create a menu
> popup = Menu(root, tearoff=0)
> popup.add_radiobutton(label="SourceIP", command= hello) # ,
> command=next) etc...
> popup.add_radiobutton(label="DestIP", command= hello)
> popup.add_radiobutton(label="Reporter'sIP", command= hello)
> popup.add_radiobutton(label="Observer'sIP", command= hello)
> popup.add_separator()
> popup.add_radiobutton(label="Home")
>
> def do_popup(event):
>     # display the popup menu
>     try:
>         popup.post(event.x_root, event.y_root)
>     finally:
>         # make sure to release the grab (Tk 8.0a1 only)
>         popup.grab_release()
> def hello(event= None):
>     print "hello"
>
> w.bind("<Button-3>", do_popup)
>
> b = Button(root, text="Quit", command=root.destroy)
> b.pack()
>
> mainloop()

Here's a great tutorial:

http://www.effbot.org/tkinterbook/tkinter-hello-again.htm

HTH,
Rob




More information about the Python-list mailing list