fontchooser(n)
π fontchooser(n) β the Tk Built-In Commands glow-up
okay so bestie, welcome to fontchooser(n), one of the Tk Built-In Commands, and honestly? she's the queen of "which font though?" energy π
β¨ NAME β¨
fontchooser β the thing that controls the font selection dialog. that's it, that's the vibe.
π¦ SYNOPSIS π¦
tk fontchooser configure ?-option value ...?
tk fontchooser show
tk fontchooser hide
three whole moods. configure, show, hide. iconic behavior tbh.
πΈ DESCRIPTION πΈ
so the tk fontchooser command is your remote control for the Tk font selection dialog π She uses the native platform font selection dialog where available, or a dialog implemented in Tcl otherwise. slay, cross-platform queen.
but here's the plot twist β unlike most of the other Tk dialog commands, tk fontchooser does not return an immediate result π because on some platforms (macOS) the standard font dialog is modeless, while on others (Windows) it is modal. to accommodate this difference, all user interaction with the dialog will be communicated to the caller via callbacks or virtual events. so like, she'll text you later instead of answering right away, fr fr.
the tk fontchooser command can have one of the following forms:
tk fontchooser configure ?-option value ...?β set or query one or more of the configuration options below (analogous to Tk widget configuration). very "let me adjust my settings" of her.tk fontchooser showβ show the font selection dialog. depending on the platform, may return immediately or only once the dialog has been withdrawn. lowkey unpredictable but we love her.tk fontchooser hideβ hide the font selection dialog if it is visible and cause any pendingtk fontchooser showcommand to return. she said "bye π" and she meant it.
π CONFIGURATION OPTIONS π
-parentβ specifies/returns the logical parent window of the font selection dialog (similar to the-parentoption to other dialogs). the font selection dialog is hidden if it is visible when the parent window is destroyed. so like, when parent goes down, she goes down with it. ride or die π-titleβ specifies/returns the title of the dialog. has no effect on platforms where the font selection dialog does not support titles. ngl some platforms just don't wanna hear about your title ideas π-fontβ specifies/returns the font that is currently selected in the dialog if it is visible, or that will be initially selected when the dialog is shown (if supported by the platform). can be set to the empty string to indicate that no font should be selected. fonts can be specified in any form given by the "FONT DESCRIPTION" section in thefontmanual page. main character energy: she needs to know her font in advance.-commandβ specifies/returns the command prefix to be called when a font selection has been made by the user. the command prefix is evaluated at the global level after having the specification of the selected font appended. on platforms where the font selection dialog offers the user control of further font attributes (such as color), additional key/value pairs may be appended before evaluation. can be set to the empty string to indicate that no callback should be invoked. fonts are specified by a list of form [3] of the "FONT DESCRIPTION" section in thefontmanual page (i.e. a list of the form{family size style ?style ...?}). literally the "call me when you pick one" option π«Ά-visibleβ read-only option that returns a boolean indicating whether the font selection dialog is currently visible. attempting to set this option results in an error. π¨ read-only means read-only, bestie, do NOT try it.
π VIRTUAL EVENTS π
<<TkFontchooserVisibility>>β sent to the dialog parent whenever the visibility of the font selection dialog changes, both as a result of user action (e.g. disposing of the dialog via OK/Cancel button or close box) and of thetk fontchooser show/hidecommands being called. binding scripts can determine the current visibility of the dialog by querying the-visibleconfiguration option. she's telling you she showed up. or left. either way, you're getting the notification β¨<<TkFontchooserFontChanged>>β sent to the dialog parent whenever the font selection dialog is visible and the selected font changes, both as a result of user action and of the-fontconfiguration option being set. binding scripts can determine the currently selected font by querying the-fontconfiguration option. "new font, who dis" β the event π
π₯ NOTES π₯
callers should not expect a result from tk fontchooser show and may not assume that the dialog has been withdrawn or closed when the command returns π all user interaction with the dialog is communicated to the caller via the -command callback and the <<TkFontchooser*>> virtual events. it is implementation dependent which exact user actions result in the callback being called resp. the virtual events being sent. where an Apply or OK button is present in the dialog, that button will trigger the -command callback and <<TkFontchooserFontChanged>> virtual event. on some implementations other user actions may also have that effect; on macOS for instance, the standard font selection dialog immediately reflects all user choices to the caller. so like, macOS is the friend who replies instantly and everyone else is on read receipts π
in the presence of multiple widgets intended to be influenced by the font selection dialog, care needs to be taken to correctly handle focus changes: the font selected in the dialog should always match the current font of the widget with the focus, and the -command callback should only act on the widget with the focus. the recommended practice is to set font dialog -font and -command configuration options in per-widget <FocusIn> handlers (and if necessary to unset them β i.e. set to the empty string β in corresponding <FocusOut> handlers). this is particularly important for implementers of library code using the font selection dialog, to avoid conflicting with application code that may also want to use the dialog. tl;dr: whoever has focus is the one she's talking to, no mixed signals π
because the font selection dialog is application-global, in the presence of multiple interpreters calling tk fontchooser, only the -command callback set by the interpreter that most recently called tk fontchooser configure or tk fontchooser show will be invoked in response to user action and only the -parent set by that interpreter will receive <<TkFontchooser*>> virtual events. so like... last one to configure gets the texts. everyone else is left on delivered π«
the font dialog implementation may only store (and return) font actual data as the value of the -font configuration option. this can be an issue when -font is set to a named font: if that font is subsequently changed, the font dialog -font option needs to be set again to ensure its selected font matches the new value of the named font. so yeah, named font updates don't auto-propagate in there β you gotta re-tell her π
β EXAMPLE β
this one's a whole demo, and she ate:
proc fontchooserDemo {} {
wm title . "Font Chooser Demo"
tk fontchooser configure -parent .
button .b -command fontchooserToggle -takefocus 0
fontchooserVisibility .b
bind . <<TkFontchooserVisibility>> \
[list fontchooserVisibility .b]
foreach w {.t1 .t2} {
text $w -width 20 -height 4 -borderwidth 1 -relief solid
bind $w <FocusIn> [list fontchooserFocus $w]
$w insert end "Text Widget $w"
}
.t1 configure -font {Courier 14}
.t2 configure -font {Times 16}
pack .b .t1 .t2; focus .t1
}
proc fontchooserToggle {} {
tk fontchooser [expr {
[tk fontchooser configure -visible] ?
"hide" : "show"}]
}
proc fontchooserVisibility {w} {
$w configure -text [expr {
[tk fontchooser configure -visible] ?
"Hide Font Dialog" : "Show Font Dialog"}]
}
proc fontchooserFocus {w} {
tk fontchooser configure -font [$w cget -font] \
-command [list fontchooserFontSelection $w]
}
proc fontchooserFontSelection {w font args} {
$w configure -font [font actual $font]
}
fontchooserDemo
the way that fontchooserFocus wires up -font and -command per widget with focus?? that's the whole notes section in action. study her π
π§ SEE ALSO π§
font(n), tk(n) β go read those too, bestie, they're the lore.
π KEYWORDS π
dialog, font, font selection, font chooser, font panel
and that's the whole page, no cap π
cute little sign-off: this one comes to you from Tk, filed under fontchooser(n) in the Tk Built-In Commands section, and yes there's no fancy date on the footer so don't come for me π go make something pretty with it β you're gonna slay π«Άβ¨
π¦ where this page comes from
- alpine 3.22: tk-doc 8.6.16-r0 Β· TCL
- alpine 3.23: tk-doc 8.6.17-r0 Β· TCL
- alpine 3.23: tk9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tk-doc 8.6.17-r1 Β· TCL
- alpine 3.24: tk9-doc 9.0.3-r2 Β· TCL
- arch rolling: tk 8.6.16-1 Β· TCL
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- nixos 26.05: tk 9.0.3
- nixpkgs unstable: tk 9.1.0
- Copyright (c) 2008 Daniel A. Steffen <das@users.sourceforge.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms