Changing the font size of anOptionMenu widget

Discussion in 'Python' started by Angel, Jan 24, 2013.

  1. Angel

    Angel Guest

    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.
    Angel, Jan 24, 2013
    #1
    1. Advertising

  2. Angel

    Rick Johnson Guest

    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)"..
    Rick Johnson, Jan 25, 2013
    #2
    1. Advertising

  3. Angel

    Angel Guest

    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!
    Angel, Jan 25, 2013
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dave richards
    Replies:
    2
    Views:
    600
    Paul Furman
    Feb 19, 2004
  2. wial
    Replies:
    2
    Views:
    804
  3. mttc
    Replies:
    2
    Views:
    2,370
    Roedy Green
    Jul 3, 2009
  4. Kamaljeet Saini
    Replies:
    0
    Views:
    389
    Kamaljeet Saini
    Feb 13, 2009
  5. Replies:
    0
    Views:
    322
Loading...

Share This Page