paramter passing question
diffuser78 at gmail.com
diffuser78 at gmail.com
Wed Aug 9 13:18:16 EDT 2006
It partly works but I get error printed out on the console.
Traceback (most recent call last):
File "NewProject.py", line 87, in OnEdit
win = MyFrame4(self, -1, "",sim_name=sim_name)
File "NewProject.py", line 1098, in __init__
wx.Frame.__init__(self, *args, **kwds)
File
"/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_windows.py",
line 476, in __init__
newobj = _windows_.new_Frame(*args, **kwargs)
TypeError: 'sim_name' is an invalid keyword argument for this function
Larry Bates wrote:
> diffuser78 at gmail.com wrote:
> > I wrote a small app in wxPython using wxGlade as designer tool. wxGlade
> > brings and writes a lot of code by itself and thats where my confusion
> > started. Its about parameter passing. Here is my little confusion.
> >
> > ***************CODE BEGINS************************************
> > class MyFrame1(wx.Frame):
> > def __init__(self, *args, **kwds):
> > .....
> > .....
> > def OnEdit(self, event):
> > sim_name = 'some_string'
> > win = MyFrame2(self, -1, "")
> > win.Show(True)
> > ********************************************************************
> >
> > class MyFrame2(wx.Frame):
> > def __init__(self, *args, **kwds):
> > .....
> > .....
> > def onLaunch(self, event):
> > ## This function needs to use the parameter sim_name which is
> > in class MyFrame1-->OnEdit
> > ***************CODE ENDS************************************
> >
> > I want to pass sim_name parameter to MyFrame2 in def OnEdit function
> > but I don't know how to do it. I tried couple of things but always got
> > some error. I have done some parameter passing in normal Python code
> > but *args and **kwds is a little confusing.
> >
> > Could you please tell me how to send parameter "sim_name" from
> > MyFrame1(in OnEdit function) and how to recieve it in MyFrame2 so that
> > I can use that parameter in MyFrame2 namespace.
> >
> > Every help is appreciated.
> >
> > Thanks
> >
> How about using the keyword args to pass it:
>
> class MyFrame1(wx.Frame):
> def __init__(self, *args, **kwds):
> .....
> .....
> def OnEdit(self, event):
> sim_name = 'some_string'
> win = MyFrame2(self, -1, "", sim_name=sim_name)
> win.Show(True)
> ********************************************************************
>
> class MyFrame2(wx.Frame):
> def __init__(self, *args, **kwds):
> .....
> .....
> self.sim_name=kwds.get('sim_name', 'default sim_name')
>
> def onLaunch(self, event):
> ## This function needs to use the parameter sim_name which is
> ## self.sim_name can be used here
>
> -Larry Bates
More information about the Python-list
mailing list