1 # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
5 # Tix Demostration Program
7 # This sample program is structured in such a way so that it can be
8 # executed from the Tix demo program "tixwidgets.py": it must have a
9 # procedure called "RunSample". It should also have the "if" statment
10 # at the end of this file so that it can be run as a standalone
13 # This file demonstrates the use of the tixControl widget -- it is an
14 # entry widget with up/down arrow buttons. You can use the arrow buttons
15 # to adjust the value inside the entry widget.
17 # This example program uses three Control widgets. One lets you select
18 # integer values; one lets you select floating point values and the last
19 # one lets you select a few names.
26 control
= DemoControl(root
)
31 def __init__(self
, w
):
35 global demo_maker
, demo_thrust
, demo_num_engines
37 demo_maker
= Tix
.StringVar()
38 demo_thrust
= Tix
.DoubleVar()
39 demo_num_engines
= Tix
.IntVar()
41 demo_thrust
.set(20000.0)
42 demo_num_engines
.set(2)
44 top
= Tix
.Frame(w
, bd
=1, relief
=Tix
.RAISED
)
46 # $w.top.a allows only integer values
48 # [Hint] The -options switch sets the options of the subwidgets.
49 # [Hint] We set the label.width subwidget option of the Controls to
50 # be 16 so that their labels appear to be aligned.
52 a
= Tix
.Control(top
, label
='Number of Engines: ', integer
=1,
53 variable
=demo_num_engines
, min=1, max=4,
54 options
='entry.width 10 label.width 20 label.anchor e')
56 b
= Tix
.Control(top
, label
='Thrust: ', integer
=0,
57 min='10000.0', max='60000.0', step
=500,
59 options
='entry.width 10 label.width 20 label.anchor e')
61 c
= Tix
.Control(top
, label
='Engine Maker: ', value
='P&W',
63 options
='entry.width 10 label.width 20 label.anchor e')
65 # We can't define these in the init because the widget 'c' doesn't
66 # exist yet and we need to reference it
67 c
['incrcmd'] = lambda w
=c
: adjust_maker(w
, 1)
68 c
['decrcmd'] = lambda w
=c
: adjust_maker(w
, -1)
69 c
['validatecmd'] = lambda w
=c
: validate_maker(w
)
71 a
.pack(side
=Tix
.TOP
, anchor
=Tix
.W
)
72 b
.pack(side
=Tix
.TOP
, anchor
=Tix
.W
)
73 c
.pack(side
=Tix
.TOP
, anchor
=Tix
.W
)
75 box
= Tix
.ButtonBox(w
, orientation
=Tix
.HORIZONTAL
)
76 box
.add('ok', text
='Ok', underline
=0, width
=6,
78 box
.add('cancel', text
='Cancel', underline
=0, width
=6,
80 box
.pack(side
=Tix
.BOTTOM
, fill
=Tix
.X
)
81 top
.pack(side
=Tix
.TOP
, fill
=Tix
.BOTH
, expand
=1)
84 # tixDemo:Status "Selected %d of %s engines each of thrust %d", (demo_num_engines.get(), demo_maker.get(), demo_thrust.get())
92 self
.root
.tk
.dooneevent(TCL_ALL_EVENTS
)
97 maker_list
= ['P&W', 'GE', 'Rolls Royce']
99 def adjust_maker(w
, inc
):
100 i
= maker_list
.index(demo_maker
.get())
102 if i
>= len(maker_list
):
105 i
= len(maker_list
) - 1
107 # In Tcl/Tix we should return the string maker_list[i]. We can't
108 # do that in Tkinter so we set the global variable. (This works).
109 demo_maker
.set(maker_list
[i
])
111 def validate_maker(w
):
113 i
= maker_list
.index(demo_maker
.get())
115 # Works here though. Why ? Beats me.
117 # Works here though. Why ? Beats me.
120 if __name__
== '__main__':