Tkinter bind single key

John Hunter jdhunter at nitace.bsd.uchicago.edu
Tue Nov 6 11:01:28 EST 2001


>>>>> "Prabhu" == Prabhu Ramachandran <prabhu at aero.iitm.ernet.in> 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:

#!/usr/local/bin/python

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)
frame.pack()
root.mainloop()



More information about the Python-list mailing list