返回顶部

收藏

Image button mouse action: mouse in, out and rollover

更多
from Tkinter import *
from tkMessageBox import *

class PlainAndFancy( Frame ):
   def __init__( self ):
      Frame.__init__( self )
      self.pack( expand = YES, fill = BOTH )
      self.master.title( 'Buttons' )

      self.myImage = PhotoImage( file = 'logotiny.gif' )
      self.fancyButton = Button( self, image = self.myImage,
                                       command = self.pressedFancy )
      self.fancyButton.bind( '<Enter>', self.rolloverEnter )
      self.fancyButton.bind( '<Leave>', self.rolloverLeave )
      self.fancyButton.pack( side = LEFT, padx = 5, pady = 5 )

   def pressedFancy( self ):
      showinfo( 'Message', 'You pressed: Fancy Button' )

   def rolloverEnter( self, event ):
      event.widget.config( relief = GROOVE )

   def rolloverLeave( self, event ):
      event.widget.config( relief = RAISED )

def main():
   PlainAndFancy().mainloop()

if __name__ == '__main__':
   main()

标签:Python,Event

收藏

0人收藏

支持

0

反对

0