from Tkinter import *
class CheckFont( Frame ):
def __init__( self ):
Frame.__init__( self )
self.pack( expand = YES, fill = BOTH )
self.master.title( "Checkbutton Demo" )
self.frame1 = Frame( self )
self.frame1.pack()
self.text = Entry( self.frame1, width = 40,
font = "Arial 10" )
self.text.insert( INSERT, "Watch the font style change" )
self.text.pack( padx = 5, pady = 5 )
self.frame2 = Frame( self )
self.frame2.pack()
self.boldOn = BooleanVar()
self.checkBold = Checkbutton( self.frame2, text = "Bold",
variable = self.boldOn, command = self.changeFont )
self.checkBold.pack( side = LEFT, padx = 5, pady = 5 )
def changeFont( self ):
desiredFont = "Arial 10"
if self.boldOn.get():
desiredFont += " bold"
self.text.config( font = desiredFont )
def main():
CheckFont().mainloop()
if __name__ == "__main__":
main()
|