473,395 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Tkinter add_cascade option_add

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
Sep 14 '05 #1
6 4440
On Tue, 13 Sep 2005 22:31:31 -0600, Bob Greschke <bo*@greschke.com> wrote:
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.


option_add('*Menu.font', 'helvetica 12 bold') works for me for all sorts of menu items (cascade, commands, checkbuttons, whatever...).

What is your platform? There may be a few limitations for menu fonts on Windows.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"
Sep 14 '05 #2
You can set the font for the labels on the menu bar, and you can set the
font of the items in the drop down portion independently (except on Windows
where you cannot control the font of the menu bar labels). I just don't
know how to set the font for the menu bar labels using an option_add
command.

....option_add("*Menu*font", "Helvetica 12 bold") works fine
....option_add("*Cascade*font", "Helvetica 12 bold") does not,

because I can't figure out what to put in for "Cascade". There must be
something, because I can use font = "Helvetica 12 bold" in the add_cascade
command OK (see below).

The program runs on Windows, Linux, Solaris, Mac.

Bob

"Eric Brunel" <er*********@despammed.com> wrote in message
news:op**************@eb.pragmadev...
On Tue, 13 Sep 2005 22:31:31 -0600, Bob Greschke <bo*@greschke.com> wrote:
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.


option_add('*Menu.font', 'helvetica 12 bold') works for me for all sorts
of menu items (cascade, commands, checkbuttons, whatever...).

What is your platform? There may be a few limitations for menu fonts on
Windows.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"

Sep 14 '05 #3
On Wed, 14 Sep 2005 09:58:25 -0600, Bob Greschke <bo*@passcal.nmt.edu> wrote:
"Eric Brunel" <er*********@despammed.com> wrote in message
news:op**************@eb.pragmadev...
On Tue, 13 Sep 2005 22:31:31 -0600, Bob Greschke <bo*@greschke.com> wrote:
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.


option_add('*Menu.font', 'helvetica 12 bold') works for me for all sorts
of menu items (cascade, commands, checkbuttons, whatever...).

What is your platform? There may be a few limitations for menu fonts on
Windows.

You can set the font for the labels on the menu bar, and you can set the
font of the items in the drop down portion independently (except on Windows
where you cannot control the font of the menu bar labels). I just don't
know how to set the font for the menu bar labels using an option_add
command.

...option_add("*Menu*font", "Helvetica 12 bold") works fine
...option_add("*Cascade*font", "Helvetica 12 bold") does not,

because I can't figure out what to put in for "Cascade". There must be
something, because I can use font = "Helvetica 12 bold" in the add_cascade
command OK (see below).


I'm still not sure what your exact requirements are. Do you want to have a different font for the menu bar labels and the menu items and to set them via an option_add? If it is what you want, I don't think you can do it: the menus in the menu bar are just ordinary items for tk, and you can't control separately the different kind of menu items. In addition, you can have cascade menus in "regular" menus, like in:

--------------------------------------
from Tkinter import *

root = Tk()

menuBar = Menu(root)
root.configure(menu=menuBar)

fileMenu = Menu(menuBar)
menuBar.add_cascade(label='File', menu=fileMenu)

openRecentMenu = Menu(fileMenu)
fileMenu.add_cascade(label='Open recent', menu=openRecentMenu)

openRecentMenu.add_command(label='foo.txt')
openRecentMenu.add_command(label='bar.txt')

fileMenu.add_command(label='Quit', command=root.quit)

root.mainloop()
--------------------------------------

All menu items get the options you defined via option_add('*Menu.*', ...), whether they are cascade or commands or whatever. Not doing so would end up in quite weird results.

To do what you seem to want, I'd create a custom class for menu bars like this:

--------------------------------------
from Tkinter import *

class MyMenuBar(Menu):

def __init__(self, master, **options):
Menu.__init__(self, master, **options)
master.configure(menu=self)

def add_cascade(self, **options):
if not options.has_key('font'):
options['font'] = ('helvetica', 14, 'bold')
Menu.add_cascade(self, **options)
root = Tk()

menuBar = MyMenuBar(root)

fileMenu = Menu(menuBar)
menuBar.add_cascade(label='File', menu=fileMenu)

openRecentMenu = Menu(fileMenu)
fileMenu.add_cascade(label='Open recent', menu=openRecentMenu)

openRecentMenu.add_command(label='foo.txt')
openRecentMenu.add_command(label='bar.txt')

fileMenu.add_command(label='Quit', command=root.quit)

root.mainloop()
--------------------------------------
This prevents you from putting the font=... option in all menus you create in your menu bar without the need for an option_add.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"
Sep 15 '05 #4
Eric Brunel wrote in reply to Bob Greschke:
I'm still not sure what your exact requirements are. Do you want to have
a different font for the menu bar labels and the menu items and to set
them via an option_add? If it is what you want, I don't think you can do
it: the menus in the menu bar are just ordinary items for tk, and you
can't control separately the different kind of menu items.


I guess he has the same problem as I have. See sample code:

from Tkinter import *
class App(Tk):
def __init__(self):
Tk.__init__(self)
self.option_add('*Menu.font', 'helvetica 24 bold')
self.menuBar=Menu(self)
self.fileMenu=Menu(self.menuBar,tearoff=0)
self.subMenu=Menu(self.fileMenu)
self.fileMenu.add_cascade(label='foo', menu=self.subMenu)
self.subMenu.add_command(label='bar',command=self. foo)
self.subMenu.add_command(label='baz',command=self. foo)
self.fileMenu.add_command(label='Quit',command=sel f.quit)
self.menuBar.add_cascade(label='File',menu=self.fi leMenu)
self.config(menu=self.menuBar)
def foo(self):
pass
app=App()
app.mainloop()

What happens on my WinXP-box when I run this code is that the menu bar
still is displayed in the standard font, which seems to be Helvetica 8.
I.e. The text 'File' is still small, while everything else in the menus
is displayed in Helvetica 24 bold. Adding font=... to any of the
commands above does not change the appearance of 'File'. I have no
problems changing the appearance of any individual text in the menu
except for the mentioned 'File'. I can change the appearance of 'foo' in
the self.fileMenu.add_cascade row, but nothing happens to 'File' if I
try to specify a font in the self.menuBar.add_cascade row. Doesn't that
seem a bit peculiar?

But... The example you gave does not change the appearance of the menus
at all on my machine. I guess it was supposed to?

Is this simply a Windows-issue that cannot easily be solved? Or is it
possibly so that this just happens to be a problem on a few
ill-configured computers? Or am I possibly blind?

/MiO
Sep 15 '05 #5
On Thu, Sep 15, 2005 at 06:11:18PM +0200, Mikael Olofsson wrote:
Is this simply a Windows-issue that cannot easily be solved? Or is it
possibly so that this just happens to be a problem on a few
ill-configured computers? Or am I possibly blind?


Here's a section from the menu(n) manpage for Tcl.

It would appear that the font for the menubar is one of the things which
happens 'according to the interface guidelines of their platforms' on
win32-family systems.

MENUBARS
Any menu can be set as a menubar for a toplevel window (see toplevel
command for syntax). On the Macintosh, whenever the toplevel is in
front, this menu's cascade items will appear in the menubar across the
top of the main monitor. On Windows and Unix, this menu's items willbe
displayed in a menubar accross the top of the window. These menus will
behave according to the interface guidelines of their platforms. For
every menu set as a menubar, a clone menu is made. See the CLONES sec-
tion for more information.

As noted, menubars may behave differently on different platforms. One
example of this concerns the handling of checkbuttons and radiobuttons
within the menu. While it is permitted to put these menu elements on
menubars, they may not be drawn with indicators on some platforms, due
to system restrictions.

On Windows, the font used for the menu can be ajusted by the user for all
applications (except those which go out of their way to ignore the user's
preferences) using the Display item in Control Panel.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFDKZ//Jd01MZaTXX0RAkrzAKCRCltiBUSp/01xaUrcIFr5no5DtwCgjPsO
N+OJJdHvDDDs1c91NEKDKBk=
=kcn+
-----END PGP SIGNATURE-----

Sep 15 '05 #6
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" <bo*@greschke.com> wrote in message
news:s-********************@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

Sep 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
2
by: James Ash | last post by:
I'm writing a very simple and small Ptyhon/Tkinter application and I'm having trouble getting the menus to appear correctly. Rather than a name appearing on the menu bar, I see "()" instead. ...
1
by: midtoad | last post by:
I'm trying to display a GIF image in a label as the central area to a Tkinter GUI. The image does not appear, though a space is made for it. Why is this so? I notice that I can display a GIF...
1
by: Bob Greschke | last post by:
Root.option_add("*Menu.Font", "Veranda 9") as an example, works fine in my program. Root.option_add("*Radiobutton*selectColor", "black") also works fine for regular radiobuttons. What I...
2
by: Bob Greschke | last post by:
I can't get Root.option_add("*Entry*highlightthickness", "2") Root.option_add("*Entry*highlightcolor", "green") to work. Anyone know why? Setting the font, background color, etc. this way...
2
by: Bob Greschke | last post by:
Option adding "Menu*font" changes the font size of the _commands, _radiobuttons, etc., but not the "File", "Edit", etc. labels on the menubar itself. What is the name for those labels? If I go ...
1
by: C D Wood | last post by:
To whom this may concern, Below is the source code, which demonstrates a problem I am having making a GUI for my python project work. 'table.txt' is a file that is read from the same folder....
2
by: Helmut Jarausch | last post by:
Hi, I am to convert an old Perl-Tk script to Python. It starts by my $MW= new MainWindow; $MW->setPalette(background ='AntiqueWhite1', foreground ='blue'); Is there an equivalent for...
3
by: joshdw4 | last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes, it's that pesky root window and I have tried withdraw to no avail. I'm assuming this is because of the methods I'm using. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.