Keypress Input

Laura Creighton lac at openend.se
Wed Jun 3 14:59:04 EDT 2015


Tkinter runs on raspberry pi.

Get it installed, and then run this program.

from Tkinter import *
root = Tk()
prompt = 'Press any key. Remember to keep your mouse in the cyan box. '
lab = Label(root, text=prompt, width=len(prompt), bg='cyan')
lab.pack()

def key(event):
    msg = 'event.char is %r and event.keysym is %r' % (event.char, event.keysym)
        lab.config(text=msg)

root.bind_all('<Key>', key)
root.mainloop() 

Now you will have to bind the various keys to do what it is you want.
You need to read online dociumentation for tkinter to learn how to do
this, as well as how to use tkinter in general.

Laura



More information about the Python-list mailing list