Tkinter bind single key

John Hunter jdhunter at
Tue Nov 6 17:01:28 CET 2001

>>>>> "Prabhu" == Prabhu Ramachandran <prabhu at> writes:

    Prabhu> self.__canvas.bind('<plus>', self.zoomin) or
    Prabhu> self.__canvas.bind('<KeyPress-plus>', self.zoomin)

Thanks for the suggestions, and for the pointer to keysymdef.h.
Unfortunately, I am having no luck.

I am working with the key 'z' to simplify.  All I want to do is bind
an event to the 'z' keypress.  I have tried (without success):

   frame.bind('<z>', press_z)
   frame.bind('<Key-z>', press_z)  
   frame.bind('<KeyPress-z>', press_z)     
   frame.bind('KeyPress-z', press_z)       
   frame.bind('Key-z', press_z)
   frame.bind('z', press_z)

Ditto for 'plus'

My keysymdef entries are:

   #define XK_z                   0x07a
   #define XK_plus                0x02b

Here is the test script; the mouse binding works fine:


from Tkinter import *

def press_z(event):
    print 'You pressed z'

def press_mouse(event):
    print 'You pressed mouse-1'

root = Tk()
frame = Frame(root, width=500,height=500)
frame.bind('<z>', press_z)
frame.bind('<Button-1>', press_mouse)

More information about the Python-list mailing list