wxpython parameter to EVT_MENU func

Thomas Schultz tom at tonic.de
Wed Jan 23 18:56:45 CET 2002


Thanx a lot Hans

I'll try your code, in the meantime I used a workaround with

def __init__(self, parent, log):
        global grid # makes the grid accessable for all modules
	  grid = SimpleGrid(self, log)

but maybe this can invoke memory problems

Thomas

>>>>>>>>>>>>>>>>>> Ursprüngliche Nachricht <<<<<<<<<<<<<<<<<<

Am 23.01.2002, 18:07:06, schrieb Hans Nowak <wurmy at earthlink.net> zum Thema 
Re: wxpython parameter to EVT_MENU func:


> 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