blob: afecea4c7decf5f25ef54d5b4314bdc3dd4445a6 [file] [log] [blame]
Martin v. Löwis8ec03e02002-03-17 18:19:13 +00001# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00002#
3# $Id$
4#
5# Tix Demostration Program
6#
7# This sample program is structured in such a way so that it can be
Martin v. Löwis8ec03e02002-03-17 18:19:13 +00008# executed from the Tix demo program "tixwidgets.py": it must have a
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00009# 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
11# program.
12
13# This file demonstrates the use of the tixComboBox widget, which is close
14# to the MS Window Combo Box control.
15#
16import Tix
17
18def RunSample(w):
19 global demo_month, demo_year
20
21 top = Tix.Frame(w, bd=1, relief=Tix.RAISED)
22
23 demo_month = Tix.StringVar()
24 demo_year = Tix.StringVar()
25
26 # $w.top.a is a drop-down combo box. It is not editable -- who wants
27 # to invent new months?
28 #
29 # [Hint] The -options switch sets the options of the subwidgets.
30 # [Hint] We set the label.width subwidget option of both comboboxes to
31 # be 10 so that their labels appear to be aligned.
32 #
33 a = Tix.ComboBox(top, label="Month: ", dropdown=1,
34 command=select_month, editable=0, variable=demo_month,
35 options='listbox.height 6 label.width 10 label.anchor e')
36
37 # $w.top.b is a non-drop-down combo box. It is not editable: we provide
38 # four choices for the user, but he can enter an alternative year if he
39 # wants to.
40 #
41 # [Hint] Use the padY and anchor options of the label subwidget to
42 # align the label with the entry subwidget.
43 # [Hint] Notice that you should use padY (the NAME of the option) and not
44 # pady (the SWITCH of the option).
45 #
46 b = Tix.ComboBox(top, label="Year: ", dropdown=0,
47 command=select_year, editable=1, variable=demo_year,
48 options='listbox.height 4 label.padY 5 label.width 10 label.anchor ne')
49
50 a.pack(side=Tix.TOP, anchor=Tix.W)
51 b.pack(side=Tix.TOP, anchor=Tix.W)
52
53 a.insert(Tix.END, 'January')
54 a.insert(Tix.END, 'February')
55 a.insert(Tix.END, 'March')
56 a.insert(Tix.END, 'April')
57 a.insert(Tix.END, 'May')
58 a.insert(Tix.END, 'June')
59 a.insert(Tix.END, 'July')
60 a.insert(Tix.END, 'August')
61 a.insert(Tix.END, 'September')
62 a.insert(Tix.END, 'October')
63 a.insert(Tix.END, 'November')
64 a.insert(Tix.END, 'December')
65
66 b.insert(Tix.END, '1992')
67 b.insert(Tix.END, '1993')
68 b.insert(Tix.END, '1994')
69 b.insert(Tix.END, '1995')
70 b.insert(Tix.END, '1996')
71
72 # Use "tixSetSilent" to set the values of the combo box if you
73 # don't want your -command procedures (cbx:select_month and
74 # cbx:select_year) to be called.
75 #
76 a.set_silent('January')
77 b.set_silent('1995')
78
79 box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL)
80 box.add('ok', text='Ok', underline=0, width=6,
81 command=lambda w=w: ok_command(w))
82 box.add('cancel', text='Cancel', underline=0, width=6,
83 command=lambda w=w: w.destroy())
84 box.pack(side=Tix.BOTTOM, fill=Tix.X)
85 top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
86
87def select_month(event=None):
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000088 # tixDemo:Status "Month = %s" % demo_month.get()
89 pass
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000090
91def select_year(event=None):
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000092 # tixDemo:Status "Year = %s" % demo_year.get()
93 pass
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000094
95def ok_command(w):
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000096 # tixDemo:Status "Month = %s, Year= %s" % (demo_month.get(), demo_year.get())
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000097 w.destroy()
98
99if __name__ == '__main__':
100 root = Tix.Tk()
101 RunSample(root)
102 root.mainloop()