[Tutor] re.Binding Events

prasad rao prasadaraon50 at gmail.com
Tue Feb 10 06:41:37 CET 2009


HelloI tried various permutations of the code.Nothing worked.
I am mixing 2 examples given in "an-introduction-to- tkinter "
by Fredrik Lundh.(and got this code)
Today I got this error message

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    pp()
  File "<pyshell#4>", line 18, in pp
    xx=app(root,event)
NameError: global name 'event' is not defined

Example1=
# File: hello2.py
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
self.button.pack(side=LEFT)
self.hi_there = Button(frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=LEFT)
def say_hi(self):
print "hi there, everyone!"
root = Tk()
app = App(root)
root.mainloop()
Running the Example
Example2=
# File: bind1.py
from Tkinter import *
root = Tk()
def callback(event):
print "clicked at", event.x, event.y
frame = Frame(root, width=100, height=100)
frame.bind("<Button-1>", callback)
frame.pack()
root.mainloop()
How can I mix the two?
Prasad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090210/9b042899/attachment.htm>


More information about the Tutor mailing list