]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-10/add_items.py
3 class MyFrame(wx
.Frame
):
5 wx
.Frame
.__init
__(self
, None, -1,
8 self
.txt
= wx
.TextCtrl(p
, -1, "new item")
9 btn
= wx
.Button(p
, -1, "Add Menu Item")
10 self
.Bind(wx
.EVT_BUTTON
, self
.OnAddItem
, btn
)
12 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
13 sizer
.Add(self
.txt
, 0, wx
.ALL
, 20)
14 sizer
.Add(btn
, 0, wx
.TOP|wx
.RIGHT
, 20)
17 self
.menu
= menu
= wx
.Menu()
18 simple
= menu
.Append(-1, "Simple menu item")
19 menu
.AppendSeparator()
20 exit
= menu
.Append(-1, "Exit")
21 self
.Bind(wx
.EVT_MENU
, self
.OnSimple
, simple
)
22 self
.Bind(wx
.EVT_MENU
, self
.OnExit
, exit
)
24 menuBar
= wx
.MenuBar()
25 menuBar
.Append(menu
, "Menu")
26 self
.SetMenuBar(menuBar
)
29 def OnSimple(self
, event
):
30 wx
.MessageBox("You selected the simple menu item")
32 def OnExit(self
, event
):
35 def OnAddItem(self
, event
):
36 item
= self
.menu
.Append(-1, self
.txt
.GetValue())
37 self
.Bind(wx
.EVT_MENU
, self
.OnNewItemSelected
, item
)
39 def OnNewItemSelected(self
, event
):
40 wx
.MessageBox("You selected a new item")
44 if __name__
== "__main__":
45 app
= wx
.PySimpleApp()