from Tkinter import *
from tkMessageBox import *
class MyClass( Frame ):
def __init__( self ):
Frame.__init__( self )
self.pack( expand = YES, fill = BOTH )
self.master.title( "Buttons" )
self.plainButton = Button( self, text = "Plain Button",command = self.pressedPlain )
self.plainButton.bind( "<Enter>", self.rolloverEnter )
self.plainButton.bind( "<Leave>", self.rolloverLeave )
self.plainButton.pack( side = LEFT, padx = 5, pady = 5 )
self.myImage = PhotoImage( file = "a.jpg" )
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 pressedPlain( self ):
showinfo( "Message", "You pressed: Plain Button" )
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 )
MyClass().mainloop()
|