PDA

View Full Version : [SOLVED] Python Tkinter Keyboard Event



PropheticAngel
January 11th, 2010, 11:13 PM
I have been having issues getting a Tkinter program to see my keyboard events. It will see clicks and mouse based events but has not responded to things like <F1> or <Up>

Any ideas?


#! /usr/bin/python

from Tkinter import *

root = Tk()

def callback(event):
print "You Pressed it!"

frame = Frame(root, width=100, height=100)
frame.bind("<F1>", callback)
frame.pack()

root.mainloop()

wmcbrine
January 12th, 2010, 01:13 AM
Your frame doesn't have focus. It works if you bind to root instead, or alternatively, add "frame.focus_set()" before "root.mainloop()".

PropheticAngel
January 12th, 2010, 01:32 AM
And that does it. Wonderful. Thanks.