1fontchooser(n)               Tk Built-In Commands               fontchooser(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       fontchooser - control font selection dialog
9

SYNOPSIS

11       tk fontchooser configure ?-option value -option value ...?
12
13       tk fontchooser show
14
15       tk fontchooser hide
16______________________________________________________________________________
17

DESCRIPTION

19       The  tk  fontchooser  command controls the Tk font selection dialog. It
20       uses the native platform font selection dialog where  available,  or  a
21       dialog implemented in Tcl otherwise.
22
23       Unlike  most  of  the other Tk dialog commands, tk fontchooser does not
24       return an immediate result, as on some platforms (Mac OS X)  the  stan‐
25       dard  font dialog is modeless while on others (Windows) it is modal. To
26       accommodate this difference, all user interaction with the dialog  will
27       be communicated to the caller via callbacks or virtual events.
28
29       The tk fontchooser command can have one of the following forms:
30
31       tk fontchooser configure ?-option value -option value ...?
32              Set  or  query  one  or more of the configurations options below
33              (analogous to Tk widget configuration).
34
35       tk fontchooser show
36              Show the font selection dialog. Depending on the  platform,  may
37              return immediately or only once the dialog has been withdrawn.
38
39       tk fontchooser hide
40              Hide  the  font  selection dialog if it is visible and cause any
41              pending tk fontchooser show command to return.
42

CONFIGURATION OPTIONS

44       -parent
45              Specifies/returns the logical parent window of the  font  selec‐
46              tion  dialog  (similar  to the -parent option to other dialogs).
47              The font selection dialog is hidden if it is  visible  when  the
48              parent window is destroyed.
49
50       -title Specifies/returns  the  title  of  the  dialog. Has no effect on
51              platforms where the font selection dialog does not  support  ti‐
52              tles.
53
54       -font  Specifies/returns the font that is currently selected in the di‐
55              alog if it is visible, or that will be initially  selected  when
56              the  dialog  is shown (if supported by the platform). Can be set
57              to the empty string to indicate that no font should be selected.
58              Fonts  can  be specified in any form given by the "FONT DESCRIP‐
59              TION" section in the font manual page.
60
61       -command
62              Specifies/returns the command prefix to be called  when  a  font
63              selection has been made by the user. The command prefix is eval‐
64              uated at the global level after having the specification of  the
65              selected  font  appended.  On platforms where the font selection
66              dialog offers the user control of further font attributes  (such
67              as  color),  additional  key/value  pairs may be appended before
68              evaluation. Can be set to the empty string to indicate  that  no
69              callback  should  be  invoked.  Fonts are specified by a list of
70              form [3] of the "FONT DESCRIPTION" section in  the  font  manual
71              page (i.e. a list of the form {family size style ?style ...?}).
72
73       -visible
74              Read-only  option  that returns a boolean indicating whether the
75              font selection dialog is currently visible.  Attempting  to  set
76              this option results in an error.
77
78

VIRTUAL EVENTS

80       <<TkFontchooserVisibility>>
81              Sent  to  the  dialog parent whenever the visibility of the font
82              selection dialog changes, both as a result of user action  (e.g.
83              disposing  of  the dialog via OK/Cancel button or close box) and
84              of the tk fontchooser show/hide commands being  called.  Binding
85              scripts  can  determine  the current visibility of the dialog by
86              querying the -visible configuration option.
87
88       <<TkFontchooserFontChanged>>
89              Sent to the dialog parent whenever the font selection dialog  is
90              visible  and the selected font changes, both as a result of user
91              action and of the -font configuration option being set.  Binding
92              scripts  can  determine  the currently selected font by querying
93              the -font configuration option.
94

NOTES

96       Callers should not expect a result from tk fontchooser show and may not
97       assume  that  the  dialog has been withdrawn or closed when the command
98       returns. All user interaction with the dialog is  communicated  to  the
99       caller  via  the  -command  callback and the <<TkFontchooser*>> virtual
100       events.  It is implementation dependent which exact user actions result
101       in the callback being called resp. the virtual events being sent. Where
102       an Apply or OK button is present in the dialog, that button will  trig‐
103       ger  the  -command  callback  and  <<TkFontchooserFontChanged>> virtual
104       event. On some implementations other user actions may  also  have  that
105       effect;  on  Mac  OS X for instance, the standard font selection dialog
106       immediately reflects all user choices to the caller.
107
108       In the presence of multiple widgets intended to be  influenced  by  the
109       font selection dialog, care needs to be taken to correctly handle focus
110       changes: the font selected in the dialog should always match  the  cur‐
111       rent  font  of  the  widget  with  the focus, and the -command callback
112       should only act on the widget with the focus. The recommended  practice
113       is  to  set  font  dialog  -font  and -command configuration options in
114       per-widget <FocusIn> handlers (and if necessary to unset  them  -  i.e.
115       set  to  the empty string - in corresponding <FocusOut> handlers). This
116       is particularly important for implementers of library  code  using  the
117       font  selection dialog, to avoid conflicting with application code that
118       may also want to use the dialog.
119
120       Because the font selection dialog is application-global, in  the  pres‐
121       ence of multiple interpreters calling tk fontchooser, only the -command
122       callback  set  by  the  interpreter  that  most  recently   called   tk
123       fontchooser  configure  or  tk  fontchooser show will be invoked in re‐
124       sponse to user action and only the -parent set by that interpreter will
125       receive <<TkFontchooser*>> virtual events.
126
127       The  font dialog implementation may only store (and return) font actual
128       data as the value of the -font configuration option. This can be an is‐
129       sue  when  -font  is  set to a named font, if that font is subsequently
130       changed, the font dialog -font option needs to be set again  to  ensure
131       its selected font matches the new value of the named font.
132

EXAMPLE

134              proc fontchooserDemo {} {
135                  wm title . "Font Chooser Demo"
136                  tk fontchooser configure -parent .
137                  button .b -command fontchooserToggle -takefocus 0
138                  fontchooserVisibility .b
139                  bind . <<TkFontchooserVisibility>> \
140                          [list fontchooserVisibility .b]
141                  foreach w {.t1 .t2} {
142                      text $w -width 20 -height 4 -borderwidth 1 -relief solid
143                      bind $w <FocusIn> [list fontchooserFocus $w]
144                      $w insert end "Text Widget $w"
145                  }
146                  .t1 configure -font {Courier 14}
147                  .t2 configure -font {Times 16}
148                  pack .b .t1 .t2; focus .t1
149              }
150              proc fontchooserToggle {} {
151                  tk fontchooser [expr {
152                          [tk fontchooser configure -visible] ?
153                          "hide" : "show"}]
154              }
155              proc fontchooserVisibility {w} {
156                  $w configure -text [expr {
157                          [tk fontchooser configure -visible] ?
158                          "Hide Font Dialog" : "Show Font Dialog"}]
159              }
160              proc fontchooserFocus {w} {
161                  tk fontchooser configure -font [$w cget -font] \
162                          -command [list fontchooserFontSelection $w]
163              }
164              proc fontchooserFontSelection {w font args} {
165                  $w configure -font [font actual $font]
166              }
167              fontchooserDemo
168

SEE ALSO

170       font(n), tk(n)
171

KEYWORDS

173       dialog, font, font selection, font chooser, font panel
174
175
176
177Tk                                                              fontchooser(n)
Impressum