Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_access_key_events.py
- from Tkinter import *
- root = Tk()
- root.title("Demonstrating Keystroke Events")
- root.geometry("350x50")
- def keyPressed(event):
- if event.char == event.keysym:
- message1.set('Key Pressed: %r' % event.char)
- elif len(event.char) == 1:
- message1.set('Punctuation Key: %r (%r)' % (event.keysym, event.char))
- else:
- message1.set('Special Key: %r' % event.keysym)
- def keyReleased(event):
- message1.set("Key Released " + event.char)
- message1 = StringVar()
- line1 = Label(textvariable = message1)
- message1.set("Type Any Key")
- line1.pack()
- root.bind("<KeyPress>", keyPressed)
- root.bind("<KeyRelease>", keyReleased)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement