フォントの選択をするのに便利な定型文。
青字で書かれたところだけ書き直すことができれば、あとは使い回しできそう。
なお、Tcl/tk8.6で使用可能になったものであるため、Raspberrypi標準のTcl/tkでは動作しないので注意。
#!/usr/bin/wish8.6
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" : "フォントの変更"}]
}
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]
}
wm title . "Font Chooser Demo"
tk fontchooser configure -parent .
button .b -command fontchooserToggle -takefocus 0
fontchooserVisibility .b
bind . <<TkFontchooserVisibility>> \
[list fontchooserVisibility .b]
text .t1 -width 20 -height 4 -borderwidth 1 -relief solid
bind .t1 <FocusIn> [list fontchooserFocus .t1]
.t1 insert end "美しい日本語表示を目指して AaBbCcDd"
.t1 configure -font {Times 14}
pack .b .t1; focus .t1

ttk::style configure でクラシック画面との整合がとれるみたいだったので試してみた。
新しい外観(Ttk)をわざわざ古い外観(classic)にする人は少ないだろうけど、一部を除いて何とか整合を保てた。
Tkコマンド【目次】



