Key action: Shift Pressed and Released : Key Action « Event « Python






Key action: Shift Pressed and Released

Key action: Shift Pressed and Released
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-Shift_L>", self.shiftPressed )
      self.master.bind( "<KeyRelease-Shift_L>", self.shiftReleased )

   
   def shiftPressed( self, event ):
      self.message1.set( "Shift pressed" )
      self.message2.set( "This key is left shift" )

   def shiftReleased( self, event ):
      self.message1.set( "Shift released" )
      self.message2.set( "This key is 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: any key pressedKey action: any key pressed
4.Key action: Key releasedKey action: Key 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