Advertisement
here2share

# Tk_access_key_events.py

Aug 6th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. # Tk_access_key_events.py
  2.  
  3. from Tkinter import *
  4.  
  5. root = Tk()
  6. root.title("Demonstrating Keystroke Events")
  7. root.geometry("350x50")
  8.  
  9. def keyPressed(event):
  10.     if event.char == event.keysym:
  11.         message1.set('Key Pressed: %r' % event.char)
  12.     elif len(event.char) == 1:
  13.         message1.set('Punctuation Key: %r (%r)' % (event.keysym, event.char))
  14.     else:
  15.         message1.set('Special Key: %r' % event.keysym)
  16.  
  17. def keyReleased(event):
  18.     message1.set("Key Released " + event.char)
  19.    
  20. message1 = StringVar()
  21. line1 = Label(textvariable = message1)
  22. message1.set("Type Any Key")
  23. line1.pack()
  24.  
  25. root.bind("<KeyPress>", keyPressed)
  26. root.bind("<KeyRelease>", keyReleased)
  27. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement