Tkinter add_cascade option_add

Mikael Olofsson mikael at isy.liu.se
Thu Sep 15 12:11:18 EDT 2005


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=self.quit)
         self.menuBar.add_cascade(label='File',menu=self.fileMenu)
         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



More information about the Python-list mailing list