[wxPython-users] Binding Menu Events
Phil Mayes
phil at philmayes.com
Sat Mar 15 18:00:07 PDT 2008
At 04:15 PM 3/15/2008, you wrote:
>OK,
>Update on my efforts...
>
>In the WorkoutMenu class I did this to generate the dynamic menu from a
>file....this works as desired (creates a menu item under the view menu
>for each item in the list)
>
> for i in range(len(thelist)):
> self.item = viewMenu.Append(-1, text=thelist[i])
>
>Next I did this in the MainWindow class which calls the WorkoutMenu
>class to create the menu....
>
> self.Bind(wx.EVT_MENU, self.OnViewUser(menuBar.item.Text,
>menuBar.item.GetId()), id=menuBar.item.GetId())
>
>This also seems to do what I want in that it gets the text from the
>menubar class and the id.....however, it calls the OnViewUser function
>immediately upon running the application...not what I want...it does
>nothing when I click on a View menu item.
>The OnViewUser function looks like this...
>
> def OnViewUser(self, text, myID):
> user = text
> print user, myID
> if user == "Laurel":
> print "Mike was selected."
>
>The prints are just for testing....
>
>So I feel I am getting closer....but not where I want to be.
>Does this put any ideas into anyone's head?
Your Bind call is executing the function, not passing its address. Try
something like (untested):
self.Bind(wx.Evt_MENU, self.OnViewUser)
def OnViewUser(self, event): # note only 1 param, an event object
item = event.GetEventObject()
text = self.m2f[item.GetId()]
print text
HTH, Phil
More information about the wxpython-users
mailing list