MenuBars with Chioces : Menu : Tkinker PYTHON TUTORIALS


PYTHON TUTORIALS » Tkinker » Menu »

 

MenuBars with Chioces


MenuBars with Chioces
from Tkinter import *
import Pmw
import sys

class MenuBarDemoFrame ):
   def __init__self ):
      Frame.__init__self )
      Pmw.initialise()
      self.packexpand = YES, fill = BOTH )
      self.master.title"MenuBar Demo" )
      self.master.geometry"500x200" )

      self.myBalloon = Pmw.Balloonself )
      self.choices = Pmw.MenuBarself, balloon = self.myBalloon )
      self.choices.packfill = X )

      self.choices.addmenu"File""Exit" )
      self.choices.addmenuitem"File""command", command = self.closeDemo, label = "Exit" )

      self.choices.addmenu"Format""Change font/color" 
      self.choices.addcascademenu"Format""Color" )
      self.choices.addmenuitem"Format""separator" )
      self.choices.addcascademenu"Format""Font" )

      colors = "Black""Blue""Red""Green" ]
      self.selectedColor = StringVar()
      self.selectedColor.setcolors] )

      for item in colors:      
         self.choices.addmenuitem"Color""radiobutton"
            label = item, command = self.changeColor,
            variable = self.selectedColor )

      fonts = "Times""Courier""Helvetica" ]
      self.selectedFont = StringVar()
      self.selectedFont.setfonts ] )
      
      for item in fonts:
         self.choices.addmenuitem"Font""radiobutton",
            label = item, command = self.changeFont,
            variable = self.selectedFont )

      self.choices.addmenuitem"Font""separator" )

      self.boldOn = BooleanVar()
      self.choices.addmenuitem"Font""checkbutton",label = "Bold", command = self.changeFont,variable = self.boldOn )

      self.italicOn = BooleanVar()
      self.choices.addmenuitem"Font""checkbutton",
         label = "Italic", command = self.changeFont,
         variable = self.italicOn )      

      self.display = Canvasself, bg = "white" )
      self.display.packexpand = YES, fill = BOTH )

      self.sampleText = self.display.create_text250100,text = "Sample Text", font = "Times 48" )

   def changeColorself ):
      self.display.itemconfigself.sampleText,fill = self.selectedColor.get() )

   def changeFontself ):
      newFont = self.selectedFont.get() " 48"

      if self.boldOn.get():
         newFont += " bold"

      if self.italicOn.get():
         newFont += " italic"

      self.display.itemconfigself.sampleText, font = newFont )

   def closeDemoself ):
      sys.exit()
      
MenuBarDemo().mainloop()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Tkinker
» Menu