Add comments explaining the role of the bigcomp function in dtoa.c.
[python.git] / Demo / tix / samples / ComboBox.py
blob914098715376b6ffc2e87f6dd3f09b90c9229615
1 # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
3 # $Id$
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
11 # program.
13 # This file demonstrates the use of the tixComboBox widget, which is close
14 # to the MS Window Combo Box control.
16 import Tix
18 def RunSample(w):
19 global demo_month, demo_year
21 top = Tix.Frame(w, bd=1, relief=Tix.RAISED)
23 demo_month = Tix.StringVar()
24 demo_year = Tix.StringVar()
26 # $w.top.a is a drop-down combo box. It is not editable -- who wants
27 # to invent new months?
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.
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')
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.
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).
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')
50 a.pack(side=Tix.TOP, anchor=Tix.W)
51 b.pack(side=Tix.TOP, anchor=Tix.W)
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')
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')
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.
76 a.set_silent('January')
77 b.set_silent('1995')
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)
87 def select_month(event=None):
88 # tixDemo:Status "Month = %s" % demo_month.get()
89 pass
91 def select_year(event=None):
92 # tixDemo:Status "Year = %s" % demo_year.get()
93 pass
95 def ok_command(w):
96 # tixDemo:Status "Month = %s, Year= %s" % (demo_month.get(), demo_year.get())
97 w.destroy()
99 if __name__ == '__main__':
100 root = Tix.Tk()
101 RunSample(root)
102 root.mainloop()