Radiobuttons demonstration set Font in Text : Font « 2D « Python






Radiobuttons demonstration set Font in Text

Radiobuttons demonstration set Font in Text
from Tkinter import *

class RadioFont( Frame ):
   def __init__( self ):
      Frame.__init__( self )
      self.pack( expand = YES, fill = BOTH )
      self.master.title( "Radiobutton Demo" ) 

      self.frame1 = Frame( self )
      self.frame1.pack()
      
      self.text = Entry( self.frame1, width = 40, font = "Arial 10" )
      self.text.insert( INSERT, "Font Font Font" )
      self.text.pack( padx = 5, pady = 5 )

      self.frame2 = Frame( self )
      self.frame2.pack()
      
      fontSelections = [ "Plain", "Bold", "Italic", "Bold/Italic" ]
      self.chosenFont = StringVar()

      self.chosenFont.set( fontSelections[ 0 ] ) 

      for style in fontSelections:
         aButton = Radiobutton( self.frame2, text = style,
            variable = self.chosenFont, value = style,
            command = self.changeFont )
         aButton.pack( side = LEFT, padx = 5, pady = 5 )

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

      if self.chosenFont.get() == "Bold":
         desiredFont += " bold"
      elif self.chosenFont.get() == "Italic":
         desiredFont += " italic"
      elif self.chosenFont.get() == "Bold/Italic":
         desiredFont += " bold italic"

      self.text.config( font = desiredFont )

def main():
   RadioFont().mainloop()

if __name__ == "__main__":
   main()


           
       








Related examples in the same category

1.Checkbuttons demonstration: set fontCheckbuttons demonstration: set font
2.Checkbutton to set font to boldCheckbutton to set font to bold
3.Set Button style: fontSet Button style: font
4.Set font from Root componentSet font from Root component
5.Button font: underline italicButton font: underline italic
6.Label fontLabel font