Mouse button differentiation. : Mouse « Tkinker « Python Tutorial






Mouse button differentiation.
from Tkinter import *

class MouseDetails( Frame ):
   def __init__( self ):
      Frame.__init__( self )
      self.pack( expand = YES, fill = BOTH )
      self.master.title( "Mouse clicks and buttons" )
      self.master.geometry( "350x150" )

      self.mousePosition = StringVar()
      positionLabel = Label( self,textvariable = self.mousePosition )
      self.mousePosition.set( "Mouse not clicked" )
      positionLabel.pack( side = BOTTOM )

      self.bind( "<Button-1>", self.leftClick )
      self.bind( "<Button-2>", self.centerClick )
      self.bind( "<Button-3>", self.rightClick )

   def leftClick( self, event ):
      self.showPosition( event.x, event.y )
      self.master.title( "Clicked with left mouse button" )

   def centerClick( self, event ):
      self.showPosition( event.x, event.y )
      self.master.title( "Clicked with center mouse button" )

   def rightClick( self, event ):
      self.showPosition( event.x, event.y )
      self.master.title( "Clicked with right mouse button" )

   def showPosition( self, x, y ):
      self.mousePosition.set( "Pressed at [ " + str( x ) + ", " +str( y ) + " ]" )     

MouseDetails().mainloop()








18.22.Mouse
18.22.1.Left button clickedLeft button clicked
18.22.2.Right button clickedRight button clicked
18.22.3.Drag with Left buttonDrag with Left button
18.22.4.Middle button clickedMiddle button clicked
18.22.5.Double left clickedDouble left clicked
18.22.6.Mouse events example.Mouse events example.
18.22.7.Mouse button differentiation.Mouse button differentiation.
18.22.8.Bind mouse button with action functionBind mouse button with action function