[wxPython-users] parameter passing Question
Christopher Barker
Chris.Barker at noaa.gov
Wed Aug 9 14:05:55 PDT 2006
Daniel Johnson wrote:
> The error I am getting is
> =
> Traceback (most recent call last):
> File "NewProject.py", line 87, in OnEdit
> win =3D MyFrame4(self, -1, "",sim_name=3Dsim_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 =3D _windows_.new_Frame(*args, **kwargs)
> TypeError: 'sim_name' is an invalid keyword argument for this function
It's hard to tell from just this error message, but it looks like you =
are passing the sim_name keyword argument into MyFrame4's __init__, then =
passing all the keyword args on to wx.Frame.__init__, but that doesn't =
know what to do with a sim_name keyword.
> My intial feeling is since I am using wxGlade for designing it inserts so=
me
> **kwds from stylewx.DEFAULT_FRAME_STYLE etc
That shouldn't make a difference.
> So the parameter are not being matched correctly.
That's what keyword arguments are for -- they are named, so you don't =
need to put them in any particular order.
> Is there a simple way of taking one on one parameter give that there is
> *args and **kwds in such a case.
I don't understand that question. Remember that args is a tuple, kwargs =
is a dict.:
When you call your _init__ like this:
MyFrame4(self, -1, "",sim_name=3Dsim_name)
you get:
args =3D (self, -1, "")
kwargs =3D {"sim_name": sim_name}
Does it make sense to pass those on to wx.Frame.__init__ ?
one solution is to remove the "sim_name" from kwargs:
self.sim_name =3D kwargs["sim_name"]
del kwargs["sim_name"]
then
wx.Frame.__init__(self, *args, **kwds)
or what I wrote before, putting sim_name before the other arguments.
working code is worth a thousand words. I've enclosed a demo of both =
methods in use.
> I don't want to past the code as it is around 50KB. =
This is key: ALWAYS, when you are having a problem like this, break it =
out into a tiny sample that does just the little bit you are trying to =
figure out. Then either:
A) you'll figure it out yourself as you isolate the problem
or
B) You'll have a nifty little sample to post on the list here and get =
help with.
The code I've enclosed only took me about 10 minutes to write, but it =
would have been 1 minute to fix yours if you had written it.
-Chris
-- =
Christopher Barker, Ph.D.
Oceanographer
=
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: junk.py
Type: text/x-python
Size: 984 bytes
Desc: not available
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20060=
809/ed06bd55/junk.py
More information about the wxpython-users
mailing list