[Tutor] Binding Events

Alan Gauld alan.gauld at btinternet.com
Mon Feb 9 18:17:41 CET 2009


"prasad rao" <prasadaraon50 at gmail.com> wrote

> Hi   I am unable to bind an event to a widget despite of my best 
> efforts.

So give us a clue. What happened? Do you get any error messages
in the console when you run it? Does the GUI display but just not 
respond?
Please don't make us guess...

> class app:
> def __init__(self,root):
> frame=Frame(root)
> frame.bind('<Button-1>',self.callback)
> frame.pack()
> self.event=event
> self.button=Button(root,text='quit',fg='red',command=frame.quit)
> self.button.pack(side='left')
> self.hi=Button(root,text='hi',fg='SystemWindowFrame',command=self.hi)
> self.hi.pack(side='right')
> self.callback
> def hi (self): print 'hello! there'
> def callback(self,event):
>                print "clicked at", event.x, event.y

> from Tkinter import *

Its usual to put the import at the top of the file. Not essential
but conventional.

> root=Tk()
> xx=app(root,event)

What is event? app only takes one argument not two.

> root.mainloop()

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list