[Tutor] adjust key bindings

Luke Paireepinart rabidpoobear at gmail.com
Mon Nov 27 02:29:31 CET 2006

John CORRY wrote:
> Hi All,
> I have been trying to bind the "z" key to the "Down" key using Python
> 2.4, Glade 2 and Pygtk.  I have posted this problem on the Pygtk list
> but have had no response.  I was hoping somebody on the tutor list could
> help.  I think that I am close.  I can capture the "z" key press and
> assign a "Down" key press but I can't get the "Down" key press to
> register on the Treeview in the GUI.
> Any thoughts greatly appreciated.
> Thanks,
> John.
I highly doubt that what you want to do when someone hits a 'z' is to 
generate a 'down' keypress.
What if the user assigned the down key to z?
then you'd have a
z -> down -> z -> down -> .... infinite loop.
What I expect you want is that each key, z and down, perform the same 
In other words, they both call the same function.
So basically what you'd want is something like this (non-pyGTK specific 

def aFunc():
    print "Hello, World!"

bindKey = {'down':aFunc}

keypress = raw_input("What keypress do you want to perform?")

bindKey[keypress]()#this will call the 'aFunc' function if they type 
'down', otherwise, it'll probably crash.

bindKey['z'] = aFunc

bindKey['z']()# now performs the same function as
bindkey['down']()#this does.

If you really do want to generate 'down' keypresses when someone hits 
'z', please explain why, and I will try to the best of my abilities to 
help you in that regard!
Good Luck!

More information about the Tutor mailing list