Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Changing Font sizes

1 view
Skip to first unread message

Spencer Lambert

unread,
Apr 10, 2001, 4:08:50 PM4/10/01
to
Does anyone have a good example of a program that can change the font
size and type with out restarting the program.

For example: I have a program that the user specifies the font in the
preferences. I then want to make the change automatically. How can
this be done?

Spence

Bruce Hartweg

unread,
Apr 10, 2001, 8:33:29 PM4/10/01
to
The easiest way is to create a named font (or multiple named fonts) and then
when the user changes his choice, all you need to do is update the named fonts
and all widgets get updated auto-magically. Otherwise once a new font is picked
by the user you have to recurse your widget hierarchy & use "$w config -font $newfont"
(of course only for widgets that have "-font" as a valid option)

Bruce

Jeffrey Hobbs

unread,
Apr 10, 2001, 11:14:46 PM4/10/01
to

Check out how the code for tk_setPalette in $tk_library/palette.tcl
for an example of how colors are reconfigured.

The best way though is to use named fonts from the start (see the
font command). Then you just configure that font, and all the
widgets (which should be using it) automatically adjust.

--
Jeff Hobbs The Tcl Guy
Senior Developer http://www.ActiveState.com/
Tcl Support and Productivity Solutions

Oleg Oleinick

unread,
Apr 12, 2001, 8:44:38 AM4/12/01
to

Try something like this:

---
bind all <<ChangeFont>> {
catch {%W configure -font [option get %W font widgetDefault]}
foreach w [winfo children %W] {
event generate $w <<ChangeFont>>
}
}

proc ChangeFonts {font1 font2 font3} {
option add *font $font1
option add *text*font $font2
# ...
option add *message*font $font3
event generate . <<ChangeFont>>
}

ChangeFonts Helvetica {Courier 12 bold} {{Times New Roman} 14 bold}
---

>
>Spence
>
Oleg

0 new messages