[Tkinter-discuss] tag_bind

Fredrik Lundh fredrik at pythonware.com
Tue Mar 28 22:19:31 CEST 2006


Pavel Kosina wrote:

> So in other words you would like to tell me that funcionality of
> tag_bind is broken? That it is not working in this version?

keyboard events are always sent to the item that has focus, and
you can only set focus to items that support the insertion cursor
protocol.

in stock tk/tkinter, "text" is the only item type that supports that
protocol.

</F>

#
# working keyboard tag_bind example

from Tkinter import *

def move(what):
    print what.keycode

myCanvas=Canvas(bg="white")
player=myCanvas.create_text((20, 20), text="hello", fill="blue")

myCanvas.focus(player)
myCanvas.focus_set() # <-- canvas must have focus
myCanvas.tag_bind(player, "<Up>", move)
myCanvas.pack()

mainloop()





More information about the Tkinter-discuss mailing list