Reputation: 29
Why does the following code not produce the expected result?:
from Tkinter import *
root = Tk()
def key(event):
frame.focus_set()
print "pressed", repr(event.char
frame = Frame(root, width=100, height=100)
frame.bind("<Key>", key)
frame.pack()
root.mainloop()
Upvotes: 1
Views: 129
Reputation: 3029
You need to set input focus to your frame.
Try adding frame.focus_set()
before
root.mainloop()
Upvotes: 1