Key action: any key pressed : Key Action « Event « Python






Key action: any key pressed

Key action: any key pressed
from Tkinter import *

class KeyDemo( Frame ):
   def __init__( self ):
      Frame.__init__( self )
      self.pack( expand = YES, fill = BOTH )
      self.master.title( "Demonstrating Keystroke Events" )
      self.master.geometry( "350x50" )

      self.message1 = StringVar()
      self.line1 = Label( self, textvariable = self.message1 )
      self.message1.set( "Type any key or shift" )
      self.line1.pack()

      self.message2 = StringVar()
      self.line2 = Label( self, textvariable = self.message2 )
      self.message2.set( "" )
      self.line2.pack()

      self.master.bind( "<KeyPress>", self.keyPressed )

   def keyPressed( self, event ):
      self.message1.set( "Key pressed: " + event.char )
      self.message2.set( "This key is not left shift" )
   
def main():
   KeyDemo().mainloop()

if __name__ == "__main__":
   main()

           
       








Related examples in the same category

1.Bind Key action: ReturnBind Key action: Return
2.Key event: function key and special keyKey event: function key and special key
3.Key action: Key releasedKey action: Key released
4.Key action: Shift Pressed and ReleasedKey action: Shift Pressed and Released
5.Key action: Function Key, ALt, Control, ShiftKey action: Function Key, ALt, Control, Shift
6.Key action: set Label textKey action: set Label text
7.Key action: keypressedKey action: keypressed
8.Key action: Up arrowKey action: Up arrow
9.Action Key: down arrow keyAction Key: down arrow key
10.Key action: left arrowKey action: left arrow
11.Key action: Right keyKey action: Right key
12.Key action: A KeyKey action: A Key
13.Key action: Return keyKey action: Return key
14.Key and mouse Action infomationKey and mouse Action infomation