Merged release21-maint changes.
[python/dscho.git] / Demo / tix / samples / PopMenu.py
blobc2301cf78cd1c4a7b44ec3969188c522a848672b
1 # Tix Demostration Program
2 #
3 # $Id$
6 # This sample program is structured in such a way so that it can be
7 # executed from the Tix demo program "widget": it must have a
8 # procedure called "RunSample". It should also have the "if" statment
9 # at the end of this file so that it can be run as a standalone
10 # program using tixwish.
12 # This file demonstrates the use of the tixPopupMenu widget.
14 import Tix
16 def RunSample(w):
17 # We create the frame and the button, then we'll bind the PopupMenu
18 # to both widgets. The result is, when you press the right mouse
19 # button over $w.top or $w.top.but, the PopupMenu will come up.
21 top = Tix.Frame(w, relief=Tix.RAISED, bd=1)
22 but = Tix.Button(top, text='Press the right mouse button over this button or its surrounding area')
23 but.pack(expand=1, fill=Tix.BOTH, padx=50, pady=50)
25 p = Tix.PopupMenu(top, title='Popup Test')
26 p.bind_widget(top)
27 p.bind_widget(but)
29 # Set the entries inside the PopupMenu widget.
30 # [Hint] You have to manipulate the "menu" subwidget.
31 # $w.top.p itself is NOT a menu widget.
32 # [Hint] Watch carefully how the sub-menu is created
34 p.menu.add_command(label='Desktop', underline=0)
35 p.menu.add_command(label='Select', underline=0)
36 p.menu.add_command(label='Find', underline=0)
37 p.menu.add_command(label='System', underline=1)
38 p.menu.add_command(label='Help', underline=0)
39 m1 = Tix.Menu(p.menu)
40 m1.add_command(label='Hello')
41 p.menu.add_cascade(label='More', menu=m1)
43 but.pack(side=Tix.TOP, padx=40, pady=50)
45 box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL)
46 box.add('ok', text='Ok', underline=0, width=6,
47 command=lambda w=w: w.destroy())
48 box.add('cancel', text='Cancel', underline=0, width=6,
49 command=lambda w=w: w.destroy())
50 box.pack(side=Tix.BOTTOM, fill=Tix.X)
51 top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
53 if __name__ == '__main__':
54 root = Tix.Tk()
55 RunSample(root)
56 root.mainloop()