Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame^] | 1 | # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 2 | # |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame^] | 3 | # $Id$ |
| 4 | # |
| 5 | # Tix Demostration Program |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 6 | # |
| 7 | # This sample program is structured in such a way so that it can be |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame^] | 8 | # executed from the Tix demo program "tixwidgets.py": it must have a |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 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 using tixwish. |
| 12 | |
| 13 | # This file demonstrates the use of the tixPopupMenu widget. |
| 14 | # |
| 15 | import Tix |
| 16 | |
| 17 | def RunSample(w): |
| 18 | # We create the frame and the button, then we'll bind the PopupMenu |
| 19 | # to both widgets. The result is, when you press the right mouse |
| 20 | # button over $w.top or $w.top.but, the PopupMenu will come up. |
| 21 | # |
| 22 | top = Tix.Frame(w, relief=Tix.RAISED, bd=1) |
| 23 | but = Tix.Button(top, text='Press the right mouse button over this button or its surrounding area') |
| 24 | but.pack(expand=1, fill=Tix.BOTH, padx=50, pady=50) |
| 25 | |
| 26 | p = Tix.PopupMenu(top, title='Popup Test') |
| 27 | p.bind_widget(top) |
| 28 | p.bind_widget(but) |
| 29 | |
| 30 | # Set the entries inside the PopupMenu widget. |
| 31 | # [Hint] You have to manipulate the "menu" subwidget. |
| 32 | # $w.top.p itself is NOT a menu widget. |
| 33 | # [Hint] Watch carefully how the sub-menu is created |
| 34 | # |
| 35 | p.menu.add_command(label='Desktop', underline=0) |
| 36 | p.menu.add_command(label='Select', underline=0) |
| 37 | p.menu.add_command(label='Find', underline=0) |
| 38 | p.menu.add_command(label='System', underline=1) |
| 39 | p.menu.add_command(label='Help', underline=0) |
| 40 | m1 = Tix.Menu(p.menu) |
| 41 | m1.add_command(label='Hello') |
| 42 | p.menu.add_cascade(label='More', menu=m1) |
| 43 | |
| 44 | but.pack(side=Tix.TOP, padx=40, pady=50) |
| 45 | |
| 46 | box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL) |
| 47 | box.add('ok', text='Ok', underline=0, width=6, |
| 48 | command=lambda w=w: w.destroy()) |
| 49 | box.add('cancel', text='Cancel', underline=0, width=6, |
| 50 | command=lambda w=w: w.destroy()) |
| 51 | box.pack(side=Tix.BOTTOM, fill=Tix.X) |
| 52 | top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1) |
| 53 | |
| 54 | if __name__ == '__main__': |
| 55 | root = Tix.Tk() |
| 56 | RunSample(root) |
| 57 | root.mainloop() |