What's the correct way to change the font size? The "Change" button isn't doing what I thought it would. The font changes size, but turns into some proportional font. I'm kinda new (1 day) to using TkFixedFont and its friends. I'm used to ("Monoco", 9) sort of stuff and I'm not sure I understand what's going on. Thanks! Bob Python 2.x, Tcl/Tk 8.5.x ==== #! /usr/bin/python from Tkinter import * Root = Tk() Txt = Text() Txt.pack() Txt.insert(END, "WWWWWWWWWWWW\n") Txt.insert(END, "MMMMMMMMMMMM\n") Txt.insert(END, "iiiiiiiiiiii\n") print "Before: ", Txt.cget("font") def changeFont(e = None): Txt.configure(font = (Txt.cget("font").split()[0], 9)) Root.update() print "Change: ", Txt.cget("font") return def changeFont2(e = None): Txt.configure(font = Txt.cget("font").split()[0]) Root.update() print "Change2:", Txt.cget("font") return Button(Root, text = "Change", command = changeFont).pack(side = TOP) Button(Root, text = "Change2", command = changeFont2).pack(side = TOP) Root.mainloop() ====
On Wednesday, February 29, 2012, Bob Greschke wrote:
What's the correct way to change the font size? The "Change" button isn't doing what I thought it would. The font changes size, but turns into some proportional font. I'm kinda new (1 day) to using TkFixedFont and its friends. I'm used to ("Monoco", 9) sort of stuff and I'm not sure I understand what's going on.
The best way is to use a named font. With that you can do 'myfont.configure(size=new_size)'. Then, every widget that uses that font will automatically see the change. For more information see http://www.pythonware.com/library/tkinter/introduction/x444-fonts.htm Named fonts are one of the true gems of tk. They have been part of the toolkit for probably a decade or more, and still to the best of my knowledge no popular toolkit has anything as powerful and easy to use.
On Feb 29, 2012, at 17:06, Bryan Oakley wrote:
On Wednesday, February 29, 2012, Bob Greschke wrote: What's the correct way to change the font size? The "Change" button isn't doing what I thought it would. The font changes size, but turns into some proportional font. I'm kinda new (1 day) to using TkFixedFont and its friends. I'm used to ("Monoco", 9) sort of stuff and I'm not sure I understand what's going on.
The best way is to use a named font. With that you can do 'myfont.configure(size=new_size)'. Then, every widget that uses that font will automatically see the change.
For more information see http://www.pythonware.com/library/tkinter/introduction/x444-fonts.htm
Named fonts are one of the true gems of tk. They have been part of the toolkit for probably a decade or more, and still to the best of my knowledge no popular toolkit has anything as powerful and easy to use.
Thanks Bryan. That was the kick-in-the-pants that I needed to Do The Right Thing. It looks like it's going to work out quite well. Bob
participants (2)
-
Bob Greschke -
Bryan Oakley