[Tkinter-discuss] tag_bind

Michael Lange klappnase at web.de
Mon Mar 27 11:50:00 CEST 2006


On Sun, 26 Mar 2006 22:01:17 +0200
geon <geon at post.cz> wrote:

> Hi,
> 
> On a canvas I would like to bind my "player" with arrows keys, but must 
> be there something wrong, cause it is not able to bind it. This is my code:
> 
> from Tkinter import *
> 
> def move(what):
>     print what.keycode
> 
> 
> master=Tk()
> myCanvas=Canvas(master, bg="white")
> pos=(20,20,30,30)
> player=myCanvas.create_oval(pos, fill="blue")
> 
> myCanvas.focus(player)
> myCanvas.tag_bind(player, "<Up>", move)
> myCanvas.pack()
> 
> mainloop()
> 

Hi Geon,

I don't think you can pass keyboard focus to canvas items this way, you will have to bind
to the Canvas widget itself.

Michael


More information about the Tkinter-discuss mailing list