[Tutor] Tkinter canvas movement question...

Jesse F. W jessefw@loop.com
Thu, 23 Aug 2001 10:42:33 -0700


Jason O'Dell wrote:
> Fellow list users, I JeSo (long time reader, first time poster) come =
> bearing problems... Ok, using Tkinter, I have the following code,
> 
> class dude:
>     def __init__(self):
>         self.physical =3D screen.create_oval(30,270,60,300, =
> fill=3D'white', outline=3D'white')
>     def left(self):
>         screen.move(self.physical, 5, 5)
> 
> (screen is earlier defined as a Tkinter Canvas widget)
> 
> and elsewhere i have,
> 
> circle =3D dude()
> root.bind_all('<Left>', circle.left())
Besides the passing of the results of the function insted of the 
function, I think there is another problem.  When you use any of the 
bind commands in Tkinter, the function you pass must accept an 
extra argument(normally called 'event') when it is called in response 
to the bound action(in your case, pressing the left arrow)  Your left 
command must take two arguments: self(because it's a method) 
AND event(because it's being called by a bind statement.
	I also don't think you need to use bind_all for keyboard events.  
Bind_all will bind all the widgets in the window.  As far as I know, 
only the root window gets key input, so it would be allright to just 
bind to the root window, not to the canvas(and whatever else you 
have in your code) too.
> ...Any ideas why that wont work? It simply draws up everything, with
> the = object already moved once, without any pressing of left, and
> future = pressings of left have no effect. Any help on this lil
> problem would be = appreciated...  Also, any suggestions on how I
> could best put that = binding inside the class itself?
>    Thankyou all...
>        JeSo
Yourverywelcome,
	JeWe-> Jesse F. W