paramter passing question

Larry Bates larry.bates at websafe.com
Fri Aug 4 20:15:55 EDT 2006


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