Use Check buttons to change the font : Checkbutton « Tkinker « Python Tutorial






Use Check buttons to change the font
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, "this is a test" )
      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 )

      self.italicOn = BooleanVar()

      self.checkItalic = Checkbutton( self.frame2, text = "Italic", variable = self.italicOn, command = self.changeFont )
      self.checkItalic.pack( side = LEFT, padx = 5, pady = 5 )

   def changeFont( self ):
      desiredFont = "Arial 10 bold"

      if self.boldOn.get():
         desiredFont = "Arial 10 bold"

      if self.italicOn.get():
         desiredFont = "Arial 10 italic"

      self.text.config( font = desiredFont )

CheckFont().mainloop()








18.6.Checkbutton
18.6.1.Check buttons, the easy wayCheck buttons, the easy way
18.6.2.Check buttons, the hard way (without variables)Check buttons, the hard way (without variables)
18.6.3.Checkbox button barCheckbox button bar
18.6.4.Use Check buttons to change the fontUse Check buttons to change the font
18.6.5.React to the check state of a check boxReact to the check state of a check box
18.6.6.RadioButtons and CheckButtonRadioButtons and CheckButton