1

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()
4
  • 2
    What is the expected result? Commented May 8, 2015 at 12:07
  • print "pressed", repr(event.char) that the name of the key pressed is printed. Commented May 8, 2015 at 12:19
  • 1
    Missing parenthesis, perhaps? Commented May 8, 2015 at 12:30
  • Was in the original code. Just an oversight in pasting it to the board. Commented May 8, 2015 at 13:33

1 Answer 1

1

You need to set input focus to your frame. Try adding frame.focus_set() before

root.mainloop()
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! That is the solution. Have a great weekend.
@BobPynewby you are welcome. Please don't forget to mark the answer as resolution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.