Update tk to version 8.5.5
[git/jnareb-git.git] / mingw / lib / tk8.5 / demos / ttkbut.tcl
blob3d5d3a82b04bf31e7b839c7d0cd835b2305acfc4
1 # ttkbut.tcl --
3 # This demonstration script creates a toplevel window containing several
4 # simple Ttk widgets, such as labels, labelframes, buttons, checkbuttons and
5 # radiobuttons.
7 # RCS: @(#) $Id: ttkbut.tcl,v 1.4 2007/12/13 15:27:07 dgp Exp $
9 if {![info exists widgetDemo]} {
10 error "This script should be run from the \"widget\" demo."
13 package require Tk
14 package require Ttk
16 set w .ttkbut
17 catch {destroy $w}
18 toplevel $w
19 wm title $w "Simple Ttk Widgets"
20 wm iconname $w "ttkbut"
21 positionWindow $w
23 ttk::label $w.msg -font $font -wraplength 4i -justify left -text "Ttk is the new Tk themed widget set. This is a Ttk themed label, and below are three groups of Ttk widgets in Ttk labelframes. The first group are all buttons that set the current application theme when pressed. The second group contains three sets of checkbuttons, with a separator widget between the sets. Note that the \u201cEnabled\u201d button controls whether all the other themed widgets in this toplevel are in the disabled state. The third group has a collection of linked radiobuttons."
24 pack $w.msg -side top -fill x
26 ## See Code / Dismiss
27 pack [addSeeDismiss $w.seeDismiss $w {enabled cheese tomato basil oregano happyness}]\
28 -side bottom -fill x
30 ## Add buttons for setting the theme
31 ttk::labelframe $w.buttons -text "Buttons"
32 foreach theme [ttk::themes] {
33 ttk::button $w.buttons.$theme -text $theme \
34 -command [list ttk::setTheme $theme]
35 pack $w.buttons.$theme -pady 2
38 ## Helper procedure for the top checkbutton
39 proc setState {rootWidget exceptThese value} {
40 if {$rootWidget in $exceptThese} {
41 return
43 ## Non-Ttk widgets (e.g. the toplevel) will fail, so make it silent
44 catch {
45 $rootWidget state $value
47 ## Recursively invoke on all children of this root that are in the same
48 ## toplevel widget
49 foreach w [winfo children $rootWidget] {
50 if {[winfo toplevel $w] eq [winfo toplevel $rootWidget]} {
51 setState $w $exceptThese $value
56 ## Set up the checkbutton group
57 ttk::labelframe $w.checks -text "Checkbuttons"
58 ttk::checkbutton $w.checks.e -text Enabled -variable enabled -command {
59 setState .ttkbut .ttkbut.checks.e \
60 [expr {$enabled ? "!disabled" : "disabled"}]
62 set enabled 1
63 ## See ttk_widget(n) for other possible state flags
64 ttk::separator $w.checks.sep1
65 ttk::checkbutton $w.checks.c1 -text Cheese -variable cheese
66 ttk::checkbutton $w.checks.c2 -text Tomato -variable tomato
67 ttk::separator $w.checks.sep2
68 ttk::checkbutton $w.checks.c3 -text Basil -variable basil
69 ttk::checkbutton $w.checks.c4 -text Oregano -variable oregano
70 pack $w.checks.e $w.checks.sep1 $w.checks.c1 $w.checks.c2 $w.checks.sep2 \
71 $w.checks.c3 $w.checks.c4 -fill x -pady 2
73 ## Set up the radiobutton group
74 ttk::labelframe $w.radios -text "Radiobuttons"
75 ttk::radiobutton $w.radios.r1 -text "Great" -variable happyness -value great
76 ttk::radiobutton $w.radios.r2 -text "Good" -variable happyness -value good
77 ttk::radiobutton $w.radios.r3 -text "OK" -variable happyness -value ok
78 ttk::radiobutton $w.radios.r4 -text "Poor" -variable happyness -value poor
79 ttk::radiobutton $w.radios.r5 -text "Awful" -variable happyness -value awful
80 pack $w.radios.r1 $w.radios.r2 $w.radios.r3 $w.radios.r4 $w.radios.r5 \
81 -fill x -padx 3 -pady 2
83 ## Arrange things neatly
84 pack [ttk::frame $w.f] -fill both -expand 1
85 lower $w.f
86 grid $w.buttons $w.checks $w.radios -in $w.f -sticky nwe -pady 2 -padx 3
87 grid columnconfigure $w.f {0 1 2} -weight 1 -uniform yes