Changing the font size of anOptionMenu widget

A

Angel

I am changing the font of an OptionMenu widget:

w = OptionMenu(master, variable, "one", "two", "three")

with

w.configure(....)

That changes the font of the widget but how can I change also the font (size) of the menu that appears when the mouse clicks it?

Thanks in advandce,

A.
 
R

Rick Johnson

Ignoring the fact that the Tkinter.Optionmenu is by far the worst widget inthe toolkit, not to mention that the whole idea of "Tkinter X_Variables" was a poor attempt to reuse code at the expense destroying the simple and intuitive interface of "get" and "set"; here is your answer:

## START CODE ##
from Tkinter import *
master = Tk()
variable = StringVar(master)
variable.set("one") # default value
optMenu = OptionMenu(master, variable, "one", "two", "three")
optMenu.pack()
# Get the menu
menu = optMenu.nametowidget(optMenu.menuname)
menu.configure(font=('Impact', 30))
mainloop()
## END CODE ##

PS: You could have probably intuited the answer yourself if you used the dir() function on "w". Of course you probably would have expected the Optionmenu to have a reference to the submenu. It does, however not a direct reference.

PPS: Or, if you prefer information overload you could have called "help(w)"..
 
A

Angel

Den fredagen den 25:e januari 2013 kl. 06:57:00 UTC+1 skrev Rick Johnson:
menu = optMenu.nametowidget(optMenu.menuname)
That was what I was missing, the '.nametowidget'. It worked like a charm:

o1=Tkinter.OptionMenu(t,v3, "€", "$")
o1.config(font=self.font)
o1.nametowidget(o1.menuname).config(font=self.font)

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top