wxpython parameter to EVT_MENU func

Hans Nowak wurmy at earthlink.net
Wed Jan 23 18:07:06 CET 2002


Thomas Schultz wrote:
> 
> Hi,
> 
> how can I pass an object to a function called by EVT_MENU?
> 
> I'm writing an application using wxgrid. I created a menu entry called
> SAVE. I call this function with:
> 
> EVT_MENU(self, ID_SAVE, self.Save)
> 
> def Save(self, event):
>         ....
> In Save I have no acces to the grid, I tried:
> 
> EVT_MENU(self, ID_SAVE, self.Save, grid)
> 
> def Save(self, event, grid):
>         ....
> 
> but this doesn't work.
> 
> How can I acces the grid in the function?

I usually use something like (pseudo-code!):

class MyFrame(wxFrame):
    def __init__(self, parent, id):
        wxFrame.__init__(...)
        ...create menu...
        EVT_MENU(self, ID_SAVE, self.Save)
        self.grid = MyGrid(...)
    def Save(self, event):
        # now here you can access the MyGrid instance
        # through self.grid.

I'm not exactly a wxPython expert, so maybe there are
better ways to do it. But this works for me.

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) 
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/



More information about the Python-list mailing list