1 # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
5 # Tix Demostration Program
7 # This sample program is structured in such a way so that it can be
8 # executed from the Tix demo program "tixwidgets.py": it must have a
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.
13 # This file demonstrates the use of the tixPopupMenu widget.
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.
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)
26 p
= Tix
.PopupMenu(top
, title
='Popup Test')
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
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)
41 m1
.add_command(label
='Hello')
42 p
.menu
.add_cascade(label
='More', menu
=m1
)
44 but
.pack(side
=Tix
.TOP
, padx
=40, pady
=50)
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)
54 if __name__
== '__main__':