Tkinter add_cascade option_add

Bob Greschke bob at passcal.nmt.edu
Thu Sep 15 13:42:50 EDT 2005


OK.  I give.  Here's the whole reason I'm trying to do this.

At the top of the program:
--------------------------

# Fonts: a constant nagging problem

System = sys.platform[:3].lower()
ScreenWidth = Root.winfo_screenwidth()
if System == "win":
    if ScreenWidth <= 1024:
        Root.option_add("*Button*font", "Helvetica 8 bold")
        Root.option_add("*Menu*font", "Helvetica 8 bold")
        CascadeFont = "Helvetica 8 bold"
        Root.option_add("*Text*font", "Courier 10")
    elif ScreenWidth <= 1400:
        Root.option_add("*Button*font", "Helvetica 12 bold")
        Root.option_add("*Checkbutton*font", "Helvetica 12")
        Root.option_add("*Entry*font", "Helvetica 10")
        Root.option_add("*Label*font", "Helvetica 12")
        Root.option_add("*Menu*font", "Helvetica 12 bold")
        CascadeFont = "Helvetica 12 bold"
        Root.option_add("*Radiobutton*font", "Helvetica 12")
        Root.option_add("*Text*font", "Courier 12")
elif System == "sun":
    Root.option_add("*Button*font", "Helvetica 10 bold")
    Root.option_add("*Checkbutton*font", "Helvetica 10")
    Root.option_add("*Entry*font", "Courier 10")
    Root.option_add("*Label*font", "Helvetica 10")
    Root.option_add("*Listbox*font", "Courier 10")
    Root.option_add("*Menu*font", "Helvetica 10 bold")
    CascadeFont = "Helvetica 10 bold"
    Root.option_add("*Radiobutton*font", "Helvetica 10")
    Root.option_add("*Text*font", "Courier 11")
elif System == "lin":
    Root.option_add("*Button*font", "Helvetica 12 bold")
    Root.option_add("*Checkbutton*font", "Helvetica 12")
    Root.option_add("*Entry*font", "Courier 12")
    Root.option_add("*Label*font", "Helvetica 12")
    Root.option_add("*Listbox*font", "Courier 12")
    Root.option_add("*Menu*font", "Helvetica 12 bold")
    CascadeFont = "Helvetica 12 bold"
    Root.option_add("*Radiobutton*font", "Helvetica 12")
    Root.option_add("*Text*font", "Courier 12")
Root.option_add("*Button*takeFocus", "0")
Root.option_add("*Checkbutton*anchor", "w")
Root.option_add("*Checkbutton*takeFocus", "0")
Root.option_add("*Entry*background", "white")
Root.option_add("*Entry*foreground", "black")
Root.option_add("*Entry*highlightThickness", "2")
Root.option_add("*Entry*highlightColor", "blue")
Root.option_add("*Entry*insertWidth", "3")
Root.option_add("*Listbox*background", "white")
Root.option_add("*Listbox*foreground", "black")
Root.option_add("*Listbox*takeFocus", "0")
Root.option_add("*Radiobutton*takeFocus", "0")
Root.option_add("*Scrollbar*takeFocus", "0")
Root.option_add("*Text*background", "black")
Root.option_add("*Text*foreground", "grey")
Root.option_add("*Text*takeFocus", "0")
Root.option_add("*Text*width", "0")

Then in another section:
------------------------

######################
# BEGIN: makeMenu(Win)
DebugCVar = IntVar()
LogCVar = IntVar()
LogFp = None
MsgFp = None
SetTimeRVar = StringVar()
SetTimeRVar.set("gps")
MemUnitsRVar = StringVar()
MemUnitsRVar.set("k")
DriveRpCVar = IntVar()
DriveRpCVar.set(1)

def makeMenu(Win):
    global Di
    Top = Menu(Win)
    Win.configure(menu = Top)
    Fi = Menu(Top, tearoff = 0)
    Fi.add_command(label = "Erase Messages", command = cmdMsgErase)
    Fi.add_separator()
    Fi.add_command(label = "Save Parameters", command = parmsSave)
    Fi.add_command(label = "Load Parameters", command = parmsLoad)
    Fi.add_separator()
    Fi.add_command(label = "Quit", command = progQuitter)
    Top.add_cascade(label = "File", menu = Fi, font = CascadeFont)
    Co = Menu(Top, tearoff = 0)
    Co.add_command(label = "Get Event Table", command = cmdGetET)
    Co.add_command(label = "Manual VCXO", command = cmdMVCXOForm)
    Co.add_separator()
    Co.add_command(label = "Enter A Message", command = cmdMessage)
    Co.add_separator()
    Co.add_command(label = "Label/Format USB Drives", \
            command = cmdSetLabelsFormat)
    Top.add_cascade(label = "Commands", menu = Co, font = CascadeFont)
    Op = Menu(Top, tearoff = 0)
    Op.add_radiobutton(label = "Set Time From GPS", variable = SetTimeRVar, 
\
            value = "gps", command = Command(subCont, "Rgps,pc", "time", \
            SetTimeRVar))
    Op.add_radiobutton(label = "Set Time From PC", variable = SetTimeRVar, \
            value = "pc", command = Command(subCont, "Rgps,pc", "time", \
            SetTimeRVar))
    Op.add_separator()
    Op.add_radiobutton(label = "Memory Units In KBs", \
            variable = MemUnitsRVar, value = "k")
    Op.add_radiobutton(label = "Memory Units In Blocks", \
            variable = MemUnitsRVar, value = "blocks")
    Op.add_separator()
    Op.add_checkbutton(label = "Wait For USB Drive Responses", \
            variable = DriveRpCVar, command = Command(subCont, "C1,0", 
"drv", \
            DriveRpCVar))
    Op.add_separator()
    Op.add_checkbutton(label = "Record Commands To Log", variable = LogCVar, 
\
            command = cmdLog)
    Op.add_separator()
    Op.add_checkbutton(label = "Debug Mode", variable = DebugCVar, \
            command = cmdDebug)
    Top.add_cascade(label = "Options", menu = Op, font = CascadeFont)
    Help = Menu(Top, tearoff = 0)
    Help.add_command(label = "Reset Commands", command = resetButtons)
    Help.add_command(label = "Current Working Directory", command = cmdCWD)
    Help.add_command(label = "Serial Port Scan", command = cmdPortScan)
# TESTING
#    Help.add_command(label = "Test", command = cmdTest)
    Help.add_separator()
    Help.add_command(label = "Help", command = showHelp)
    Help.add_command(label = "About", command = about)
    Top.add_cascade(label = "Help", menu = Help, font = CascadeFont)
    return
# END: makeMenu

Do you see the CascadeFont variable?  I want to get rid of that and turn 
setting the font of the .add_cascade items into an option_add function. 
Does anyone know how to do that?  What key word and tricky phrase does the 
option_add function need?

Bob


"Bob Greschke" <bob at greschke.com> wrote in message 
news:s-KdnUK6pLAuOrreRVn-uw at nmt.edu...
> Root.option_add("*?????*font", "Helvetica 12 bold")
>
> Want to get rid of the "font =":
> Widget.add_cascade(label = "File", menu = Fi, font = "Helvetica 12 bold")
>
> Does anyone know what ????? should be to control the font of the cascade 
> menus (the labels on the menu bar)?  "*Menu*font" handles the part that 
> drops down, but I can't come up with the menu bar labels part.
>
> Thanks!
>
> Bob
>
> 





More information about the Python-list mailing list