[Tkinter-discuss] Re: How to change font sizes in a Tkinter app?

Jeff Epler jepler at unpythonic.net
Sat Sep 11 19:30:08 CEST 2004


On Fri, Sep 10, 2004 at 09:53:33PM -0600, stewart at midtoad.homelinux.org wrote:
> I want to change all my menu entries to use the new font.  But,I don't see how
> to get the right name for those items to use in the list since each menu entry
> doesn't have a discrete object name, like say a button would
> (btn=Tkinter.Button, so you could have widgetlist=[btn,lbl,btn2].  I read
> something about using component() to achieve this, but the exact implementation
> escapes me - the example I saw related to notebook tabs rather than menu entries. 
> 

You'll have to use the "entryconfigure" method of the menu object.

Here's a program that changes the font of all entries of a menu:

import Tkinter

def set_menu_font(m, f):
    for i in range(m.index("end") + 1):
        t = m.type(i)
        if t in ("tearoff", "separator"): continue  # no font= option
        m.entryconfigure(i, font=f)

t = Tkinter.Tk()
m = Tkinter.Menu(t)
t.configure(menu=m)
m.insert_cascade("end", label="File", underline=0)
m.insert_cascade("end", label="Edit", underline=0)
m.insert_cascade("end", label="Help", underline=0)

b = Tkinter.Button(t, command=lambda: set_menu_font(m, ("Helvetica", 24)),
                    text="Font 1")
c = Tkinter.Button(t, command=lambda: set_menu_font(m, ("Courier", 12)),
                    text="Font 2")
b.pack(side="left")
c.pack(side="left")
t.mainloop()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20040911/29baf482/attachment.pgp


More information about the Tkinter-discuss mailing list