Bullseye! In retrospect, I even gave myself a hint when I said for other widgets (i.e. a button) you need to name both the object and its event (and differently) in wxGlade. I’ve been staring at code too long…
Thanks RD!
Subject:
Re: [wxpython-users] Re: Newbie question re:wxMenuBar events
From:
Robin Dunn robin@alldunn.com
Date:
Wed, 07 May 2008 14:10:49 -0700
To:
wxpython-users@lists.wxwidgets.org
···
Randy Rue wrote:
In the wxGlade dialog for editing menu items there is an “id” field for items. I had left it blank and I believe that’s why each item had an id of “-1” (I think this prompts the code to auto-assign some id to these objects). On the guess that this “id” field might actually name that menu choice (i.e. you might have a button called enable_ssl_button that kicks off a function called enable_ssl), I entered an id (“close_cw_menu_item”) for the close_cw menu item. Then when I generate code, running it returns a squawk "NameError: global name ‘close_cw_menu_item’ is not defined…
Use the ‘Name’ field in wxGlade for the menu items. Then you’ll get code like this:
# begin wxGlade: MyMenuBar.__init__
wx.MenuBar.__init__(self, *args, **kwds)
self.FileMenu = wx.Menu()
self.item1 = wx.MenuItem(self.FileMenu, wx.NewId(), "menu item 1", "", wx.ITEM_NORMAL)
self.FileMenu.AppendItem(self.item1)
self.item2 = wx.MenuItem(self.FileMenu, wx.NewId(), "menu item 2", "", wx.ITEM_NORMAL)
self.FileMenu.AppendItem(self.item2)
self.Append(self.FileMenu, "File")
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_MENU, self.OnItem1, self.item1)
self.Bind(wx.EVT_MENU, self.OnMenuItem2, self.item2)
# end wxGlade
Notice the Bind statements, where it is using the item instead of the ID of the menu item. I used item1 and item2 as the names of the items.
Robin Dunn Software Craftsman Java give you jitters? Relax with wxPython!
–