import Tkinter as tk def keyPress(event): if event.char in ('V', 'F', ' '): print event.char elif event.keysym not in ('Alt_r', 'Alt_L', 'F4'): print event.keysym return 'break' root = tk.Tk() entry = tk.Entry() entry.bind('<KeyPress>', keyPress) entry.pack() entry.focus() root.mainloop()
You can easily split the statement so that it changes to another form based on the key.
The event.keysym part is located event.keysym , so you can ALT-F4 close the application when you are in this widget. If you just else: return 'break' , then it will capture all other keystrokes.
It is also case sensitive capture. If you want case insensitive just change it to event.char.upper()
source share