1 Introduction
1.1 What is Tix
1.1.1 Tix for Application Programmers
mega-widgets
intro.tex.html#1-1
1-1
(Figure 1-1) The Class Hierarchy of Tix Widgets
1.1.2 Tix for Widget Developers
1.2 Getting Started: the TixControl Widget
Pre-requisites: you should be familiar with Tk widgets and
programming, or read the Tk book along with this book
1.2.1 Creating a TixControl Widget
tixControl .lawyers -label Lawyers: -max 10 -min 0
.lawyers config -integer true -step 2
intro.tex.html#1-2
1-2
-label
-max
-min
-integer
-step
2
(Figure 1-2) The TixControl Widget
configure
option add *lawyers.max 10
option add *lawyers.min 0
tixControl .lawyers -label Lawyers: -integer true
.lawyers config -step 2
intro.tex.html#1-3
1-3
mega-widgets
(Figure 1-3) The Composition of TixControl
1.2.2 Accessing The Value of a TixControl Widget
-value
-value
.c cget -value
.c
.c config -value 100
-variable
.c config -variable myvar
set myvar 100
-command
valueChanged
.c
tixControl .c -command valueChanged
Disabling Callbacks Temporarily
-disablecallback
tixControl .c -command addOne
proc addOne {value} {
.c config -disablecallback true
.c config -value [incr value]
.c config -disablecallback false
}
addOne
.c
.c
-disablecallback
addOne
addOne
every time
1.2.3 Validating User Inputs
-validatecmd
tixControl .c -value 0 -step 2 -validatecmd evenOnly
proc evenOnly {value} {
return [expr $value - ($value %2)]
}
evenOnly
evenOnly
-validatecmd
-value
1.3 Accessing The Components Inside Mega Widgets
1.3.1 Subwidgets
intro.tex.html#1.2.1
1.2.1
subwidgets
1.3.2 Subwidget Names
subwidget
name
label
entry
incr
decr
incr
decr
intro.tex.html#1-4
1-4
(Figure 1-4) Subwidgets inside TixControl Widget
1.3.3 The
subwidget
Method
subwidget
.c subwidget entry
entry
.c.frame.entry
subwidget
.c
.c subwidget entry configure -bg gray
entry
.c
configure -bg gray
.c.frame.entry configure -bg gray
configure
entry
-bg gray
gray
subwidget
.c subwidget entry icursor end
icursor
entry
end
entry
1.3.4 Chaining the
subwidget
Method
filesel.tex.html#5.1.3
5.1.3
fsbox
intro.tex.html#1.4
1.4
dir
dir
subwidget
.file
dir
fsbox
.file
.file subwidget fsbox subwidget dir
dir
.file subwidget fsbox subwidget dir configure -bd 2 -relief groove
1.3.5 Configuring Subwidget Options Using the
-options
Switch
subwidget
name
configure ...
subwidget
-options
-option
tixControl .income -label "Income: " -variable income -options {
label.width       8
label.anchor      e
entry.width       10
entry.borderWidth 3
}
tixControl .age    -label "Age: "    -variable age    -options {
label.width       8
label.anchor      e
entry.width       10
entry.borderWidth 3
}
pack .income .age -side top
(Figure 1-5) Using the
-options
switch
Unaligned Labels
Aligned Labels
(Figure 1-6) Using the
-options
Switch to Align the Labels
-options
intro.tex.html#1-5
1-5
intro.tex.html#1-6
1-6
label
.income
.age
-anchor
e
intro.tex.html#1-5
1-5
entry
intro.tex.html#1-6
1-6
intro.tex.html#1-5
1-5
-options
subwidget-option-spec
value
..
subwidget-option-spec
subwidget-name
.
option-name
label.anchor
anchor
label
entry.width
width
name
command-line switch
entry
-borderwidth
borderWidth
entry.borderWidth 3
intro.tex.html#1-5
1-5
entry.borderwidth 3
1.3.6 Configuring Subwidget Options Using the Tk Option Database
-options
option
name
.a.b.megaw
subw
.a.b.megaw.foo.bar.subw
option add *a.b.megaw*subw.option1 value1
option add *a.b.megaw*subw.option2 value2
option add *a.b.megaw.subw.option1 value1
option add *a.b.megaw.subw.option2 value2
.a.b.megaw
such a decision
is left to the mega-widget implementor and may vary in different
versions of the same mega-widget
intro.tex.html#1-7
1-7
intro.tex.html#1-5
1-5
option add *TixControl*label.width       8
option add *TixControl*label.anchor      e
option add *TixControl*entry.width       10
option add *TixControl*entry.borderWidth 3
tixControl .income -label "Income: " -variable income
tixControl .age    -label "Age: "    -variable age
pack .income .age -side top
(Figure 1-7) Using the Tk Option Database in Place of the
-options
switch
1.3.7 Caution: Restricted Access
-textvariable
entry
-font
-foreground
1.4 Another Tix Widget: TixComboBox
TixComboBox
intro.tex.html#1-8
1-8
(Figure 1-8) The TixComboBox Widget
1.4.1 Creating a TixComboBox Widget
tixComboBox .c -label "Animal:" -editable true
.c insert end cat
.c insert end dog
.c insert end pig
(Figure 1-9) Creating a ComboBox
intro.tex.html#1-9
1-9
.c
-editable
false
-validatecmd
intro.tex.html#1.4.3
1.4.3
1.4.2 Controlling the Style of the TixComboBox
-dropdown
true
-dropdown
false
-fancy
false
true
1.4.3 Static Options
-dropdown
-fancy
tixComboBox .c -dropdown true
-dropdown
after
TixComboBox .c
.c config -dropdown true
oop.tex.html#6
6
intro.tex.html#1.2.2
1.2.2
-value
-variable
-command
-validatecmd
intro.tex.html#1.2.2
1.2.2
1.4.4 Monitoring the User's Browsing Actions
-browsecmd
tixComboBox .c -browsecmd mybrowse
....
proc mybrowse {item} {
puts "user has browsed $item"
}
-browsecmd
-browsecmd
-browsecmd
-command
tixComboBox .c -dropdown false -browsecmd show_simple -command load_fullsize
.c insert end "/pkg/images/flowers.gif"
.c insert end "/pkg/images/jimmy.gif"
.c insert end "/pkg/images/ncsa.gif"
proc show_simple {filename} {
# Load in a simplified version of $filename
}
proc load_fullsize {filename} {
# Load in the full size image in $filename
}
-browsecmd
-browsecmd
bind
<Control-Shift-ButtonRelease-1>
"%x %X $w %W %w"
1.5 The TixSelect Widget
intro.tex.html#1-10
1-10
radiobutton
checkbutton
radiobutton
(Figure 1-10) The TixSelect Widget
1.5.1 Creating A TixSelect Widget
intro.tex.html#1-11
1-11
intro.tex.html#1-11
1-11
tixSelect
tixSelect .fruits -label "Fruits: " -orientation horizontal
.fruits add apple  -text Apple  -width 6
.fruits add orange -text Orange -width 6
.fruits add banana -text Banana -width 6
pack .fruits
(Figure 1-11) Creating a TixSelect Widget
Label and Orientation
intro.tex.html#1-11
1-11
-label
-orientation
-orientation
horizontal
vertical
intro.tex.html#1-12
1-12
-orientation
vertical
Creating the Button Subwidgets and Configuring
Their Appearance
add
intro.tex.html#1-11
1-11
add
option-value
option-value
intro.tex.html#1-11
1-11
-text
-width
-width
intro.tex.html#1-11
1-11
intro.tex.html#1-12
1-12
Horizontal Orientation
Vertical Orientation
(Figure 1-12) The TixSelect Widget
Accessing the Button Subwidgets
intro.tex.html#1.3.1
1.3.1
intro.tex.html#1.3.1
1.3.1
dynamic
subwidgets
add
subwidget
tixSelect .s
.s add apple  -text Apple
.s add orange -text Orange
#   Mmmm..., let's make the widget look more educated
#   by using French words
.s subwidget apple  config -text Pomme
.s subwidget orange config -text Orange
1.5.2 Specifying Selection Rules
-allowzero
-radio
-allowzero
-radio
-radio
-allowzero
false
-allowzero
false
-allowzero
false
intro.tex.html#1-13
1-13
tixSelect .sandwich -allowzero false -radio true -label "Sandwich :"
.sandwich add beef   -text Beef
.sandwich add cheese -text Cheese
.sandwich add ham    -text Ham
tixSelect .vege -allowzero false -radio false -label "Vegetable :"
.vege add bean    -text Bean
.vege add carrot  -text Carrot
.vege add lettuce -text Lettuce
(Figure 1-13) Specifying Simple Selection Rules
1.5.3 Accessing the Value of a TixSelect Widget
value
intro.tex.html#1-11
1-11
apple
"apple orange"
-value
-variable
-command
-disablecallback
-command
1.5.4 Specifying Complex Selection Rules
-validatecmd
-validatecmd
intro.tex.html#1.2
1.2
intro.tex.html#1-14
1-14
TwoMax
.fruits
TwoMax
tixSelect .fruits -label "Fruits: " -radio false -validatecmd TwoMax
.fruits add apple  -text Apple  -width 6
.fruits add orange -text Orange -width 6
.fruits add banana -text Banana -width 6
pack .fruits
proc TwoMax {value} {
if {[llength $value] > 2} {
return [lrange $value 0 1]
} else {
return $value
}
}
(Figure 1-14) Specifying More Complex Selection Rules
