Tkinter keybindings

Laura Creighton lac at
Thu Jan 9 08:43:29 CET 2003

I didn't do this for windows, but once I needed to remove the tab binding
altogether from a text widget.  There is something funny about the tab, and
bindtags let tab pass right through the text widget and into my signal
handler.  But brute force worked:

from Tkinter import *

def key_event(event):
        print 'keysym:' + event.keysym

root = Tk()
text = Text(root,height=10,width=50,font='courier 9')
text.bind("<Key>", key_event)
l_b_ts = text.bindtags()

# after the next line, the Key event wont be raised for Tabs

# now it will
print newTextBinds
newTextBinds = l_b_ts[1],l_b_ts[0],l_b_ts[2],l_b_ts[3]
text.bindtags = newTextBinds


This was about my fifth Tkinter program, and I wrote it to help
AlankarMisra who posted it as a problem on c.lang.python in 2001
sometime.   The important detail is that the method call didn't rebind 
the tab key, but rebinding it by hand worked.

Laura Creighton

More information about the Python-list mailing list