Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 1 | # Tix Demostration Program |
| 2 | # |
| 3 | # $Id$ |
| 4 | # |
| 5 | # |
| 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. |
| 11 | |
| 12 | # This file demonstrates the use of the tixPopupMenu widget. |
| 13 | # |
| 14 | import Tix |
| 15 | |
| 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. |
| 20 | # |
| 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) |
| 24 | |
| 25 | p = Tix.PopupMenu(top, title='Popup Test') |
| 26 | p.bind_widget(top) |
| 27 | p.bind_widget(but) |
| 28 | |
| 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 |
| 33 | # |
| 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) |
| 42 | |
| 43 | but.pack(side=Tix.TOP, padx=40, pady=50) |
| 44 | |
| 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) |
| 52 | |
| 53 | if __name__ == '__main__': |
| 54 | root = Tix.Tk() |
| 55 | RunSample(root) |
| 56 | root.mainloop() |