blob: d1dd46d43c9b6590768ab9c6229077f7784532b4 [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 -*-
Tim Peters182b5ac2004-07-18 06:16:08 +00002#
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00003# $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 tixOptionMenu widget -- you can
14# use it for the user to choose from a fixed set of options
15#
Benjamin Petersond6d63f52009-01-04 18:53:28 +000016import tkinter.tix
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000017
18options = {'text':'Plain Text', 'post':'PostScript', 'html':'HTML',
Tim Peters182b5ac2004-07-18 06:16:08 +000019 'tex':'LaTeX', 'rtf':'Rich Text Format'}
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000020
21def RunSample(w):
22 global demo_opt_from, demo_opt_to
23
Benjamin Petersond6d63f52009-01-04 18:53:28 +000024 demo_opt_from = tkinter.tix.StringVar()
25 demo_opt_to = tkinter.tix.StringVar()
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000026
Benjamin Petersond6d63f52009-01-04 18:53:28 +000027 top = tkinter.tix.Frame(w, bd=1, relief=tkinter.tix.RAISED)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000028
Benjamin Petersond6d63f52009-01-04 18:53:28 +000029 from_file = tkinter.tix.OptionMenu(top, label="From File Format : ",
Tim Peters182b5ac2004-07-18 06:16:08 +000030 variable=demo_opt_from,
31 options = 'label.width 19 label.anchor e menubutton.width 15')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000032
Benjamin Petersond6d63f52009-01-04 18:53:28 +000033 to_file = tkinter.tix.OptionMenu(top, label="To File Format : ",
Tim Peters182b5ac2004-07-18 06:16:08 +000034 variable=demo_opt_to,
35 options='label.width 19 label.anchor e menubutton.width 15')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000036
37 # Add the available options to the two OptionMenu widgets
38 #
39 # [Hint] You have to add the options first before you set the
Tim Peters182b5ac2004-07-18 06:16:08 +000040 # global variables "demo_opt_from" and "demo_opt_to". Otherwise
41 # the OptionMenu widget will complain about "unknown options"!
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000042 #
Skip Montanaro1e8ce582007-08-06 21:07:53 +000043 for opt in options.keys():
Tim Peters182b5ac2004-07-18 06:16:08 +000044 from_file.add_command(opt, label=options[opt])
45 to_file.add_command(opt, label=options[opt])
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000046
47 demo_opt_from.set('html')
48 demo_opt_to.set('post')
49
Benjamin Petersond6d63f52009-01-04 18:53:28 +000050 from_file.pack(side=tkinter.tix.TOP, anchor=tkinter.tix.W, pady=3, padx=6)
51 to_file.pack(side=tkinter.tix.TOP, anchor=tkinter.tix.W, pady=3, padx=6)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000052
Benjamin Petersond6d63f52009-01-04 18:53:28 +000053 box = tkinter.tix.ButtonBox(w, orientation=tkinter.tix.HORIZONTAL)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000054 box.add('ok', text='Ok', underline=0, width=6,
Tim Peters182b5ac2004-07-18 06:16:08 +000055 command=lambda w=w: ok_command(w))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000056 box.add('cancel', text='Cancel', underline=0, width=6,
Tim Peters182b5ac2004-07-18 06:16:08 +000057 command=lambda w=w: w.destroy())
Benjamin Petersond6d63f52009-01-04 18:53:28 +000058 box.pack(side=tkinter.tix.BOTTOM, fill=tkinter.tix.X)
59 top.pack(side=tkinter.tix.TOP, fill=tkinter.tix.BOTH, expand=1)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000060
61def ok_command(w):
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000062 # tixDemo:Status "Convert file from %s to %s" % ( demo_opt_from.get(), demo_opt_to.get())
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000063 w.destroy()
64
65if __name__ == '__main__':
Benjamin Petersond6d63f52009-01-04 18:53:28 +000066 root = tkinter.tix.Tk()
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000067 RunSample(root)
68 root.mainloop()