0

Python Keypresses

How can I get keypress events using Python and some modules (preferably tkinter)? :)

6th Jan 2017, 6:24 PM
Thomas John
Thomas John - avatar
2 ответов
+ 4
You can try doing something like this from Tkinter import * root = Tk() prompt = ' Press any key ' label1 = Label(root, text=prompt, width=len(prompt), bg='yellow') label1.pack() def key(event): if event.char == event.keysym: msg = 'Normal Key %r' % event.char elif len(event.char) == 1: msg = 'Punctuation Key %r (%r)' % (event.keysym, event.char) else: msg = 'Special Key %r' % event.keysym label1.config(text=msg) root.bind_all('<Key>', key) root.mainloop()
6th Jan 2017, 6:30 PM
Alex
Alex - avatar
+ 1
Ok thanks :)
6th Jan 2017, 7:47 PM
Thomas John
Thomas John - avatar