1# ttkbut.tcl --
2#
3# This demonstration script creates a toplevel window containing several
4# simple Ttk widgets, such as labels, labelframes, buttons, checkbuttons and
5# radiobuttons.
6#
7# RCS: @(#) $Id$
8
9if {![info exists widgetDemo]} {
10    error "This script should be run from the \"widget\" demo."
11}
12
13package require Tk
14package require Ttk
15
16set w .ttkbut
17catch {destroy $w}
18toplevel $w
19wm title $w "Simple Ttk Widgets"
20wm iconname $w "ttkbut"
21positionWindow $w
22
23ttk::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."
24pack $w.msg -side top -fill x
25
26## See Code / Dismiss
27pack [addSeeDismiss $w.seeDismiss $w {enabled cheese tomato basil oregano happyness}]\
28	-side bottom -fill x
29
30## Add buttons for setting the theme
31ttk::labelframe $w.buttons -text "Buttons"
32foreach theme [ttk::themes] {
33    ttk::button $w.buttons.$theme -text $theme \
34	    -command [list ttk::setTheme $theme]
35    pack $w.buttons.$theme -pady 2
36}
37
38## Helper procedure for the top checkbutton
39proc setState {rootWidget exceptThese value} {
40    if {$rootWidget in $exceptThese} {
41	return
42    }
43    ## Non-Ttk widgets (e.g. the toplevel) will fail, so make it silent
44    catch {
45	$rootWidget state $value
46    }
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
52	}
53    }
54}
55
56## Set up the checkbutton group
57ttk::labelframe $w.checks -text "Checkbuttons"
58ttk::checkbutton $w.checks.e  -text Enabled -variable enabled -command {
59    setState .ttkbut .ttkbut.checks.e \
60	    [expr {$enabled ? "!disabled" : "disabled"}]
61}
62set enabled 1
63## See ttk_widget(n) for other possible state flags
64ttk::separator   $w.checks.sep1
65ttk::checkbutton $w.checks.c1 -text Cheese  -variable cheese
66ttk::checkbutton $w.checks.c2 -text Tomato  -variable tomato
67ttk::separator   $w.checks.sep2
68ttk::checkbutton $w.checks.c3 -text Basil   -variable basil
69ttk::checkbutton $w.checks.c4 -text Oregano -variable oregano
70pack $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
72
73## Set up the radiobutton group
74ttk::labelframe $w.radios -text "Radiobuttons"
75ttk::radiobutton $w.radios.r1 -text "Great" -variable happyness -value great
76ttk::radiobutton $w.radios.r2 -text "Good" -variable happyness -value good
77ttk::radiobutton $w.radios.r3 -text "OK" -variable happyness -value ok
78ttk::radiobutton $w.radios.r4 -text "Poor" -variable happyness -value poor
79ttk::radiobutton $w.radios.r5 -text "Awful" -variable happyness -value awful
80pack $w.radios.r1 $w.radios.r2 $w.radios.r3 $w.radios.r4 $w.radios.r5 \
81	-fill x -padx 3 -pady 2
82
83## Arrange things neatly
84pack [ttk::frame $w.f] -fill both -expand 1
85lower $w.f
86grid $w.buttons $w.checks $w.radios -in $w.f -sticky nwe -pady 2 -padx 3
87grid columnconfigure $w.f {0 1 2} -weight 1 -uniform yes
88