By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,704 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,704 IT Pros & Developers. It's quick & easy.

paramter passing question

P: n/a
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

Aug 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
di********@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
Aug 5 '06 #2

P: n/a
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:
di********@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
Aug 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.