18ec03e0528d93c6b7cc9cf07d2f24e541661ba70Martin v. Löwis# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
2182b5aca27d376b08a2904bed42b751496f932f3Tim Peters#
3b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis# $Id$
4b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis#
5a850ef698e55d07173051747e96207496c6f1bdbMartin Panter# Tix Demonstration Program
6b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis#
7b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis# This sample program is structured in such a way so that it can be
88ec03e0528d93c6b7cc9cf07d2f24e541661ba70Martin v. Löwis# executed from the Tix demo program "tixwidgets.py": it must have a
9b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis# procedure called "RunSample". It should also have the "if" statment
10b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis# at the end of this file so that it can be run as a standalone
11b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis# program.
12b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis
13b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis# This file demonstrates the use of the tixButtonBox widget, which is a
14b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis# group of TK buttons. You can use it to manage the buttons in a dialog box,
15b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis# for example.
16b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis#
17b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis
18b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwisimport Tix
19b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis
20b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwisdef RunSample(w):
21b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    # Create the label on the top of the dialog box
22b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    #
23b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    top = Tix.Label(w, padx=20, pady=10, bd=1, relief=Tix.RAISED,
24182b5aca27d376b08a2904bed42b751496f932f3Tim Peters                    anchor=Tix.CENTER, text='This dialog box is\n a demonstration of the\n tixButtonBox widget')
25b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis
26b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    # Create the button box and add a few buttons in it. Set the
27b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    # -width of all the buttons to the same value so that they
28b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    # appear in the same size.
29b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    #
30b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    # Note that the -text, -underline, -command and -width options are all
31b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    # standard options of the button widgets.
32b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    #
33b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL)
34b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    box.add('ok', text='OK', underline=0, width=5,
35182b5aca27d376b08a2904bed42b751496f932f3Tim Peters            command=lambda w=w: w.destroy())
36b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    box.add('close', text='Cancel', underline=0, width=5,
37182b5aca27d376b08a2904bed42b751496f932f3Tim Peters            command=lambda w=w: w.destroy())
38b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    box.pack(side=Tix.BOTTOM, fill=Tix.X)
39b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
40b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis
41b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwisif __name__ == '__main__':
42b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    root = Tix.Tk()
43b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    RunSample(root)
44b21cb5fa7d4e820d470a4dc5a80544e0e0965c86Martin v. Löwis    root.mainloop()
45