在两个WxPython窗口之间传递变量

时间:2013-08-10 04:32:39

标签: python class parameters wxpython

所以即时编写一个程序,我需要从主GUI窗口到弹出窗口的列表,该窗口使用主窗口中的选定选项执行操作

问题是我在调用新窗口的类时无法传递变量

当我创建实例时,我想传递列表

act = Action(None, "Action")

但它只允许我传递窗口的名称,如果我尝试创建一个新参数,我会收到此错误:

Traceback (most recent call last):
  File "C:\Documents and Settings\User\Desktop\Invent Manager.py", line 274, in auction
    act = Action(None, "Action", "item")
  File "C:\Documents and Settings\User\Desktop\Invent Manager.py", line 352, in __init__
    self.InitUI()    
  File "C:\Documents and Settings\User\Desktop\Invent Manager.py", line 357, in InitUI
    main = GUI()
TypeError: __init__() takes exactly 4 arguments (1 given)

这是我弹出窗口的初始化:

def __init__(self, parent, title, item_id):
        super(Action, self).__init__(parent, title=title, 
            size=(200, 200))
        self.InitUI()    
        self.Centre()
        self.Show()
有人请告诉我如何做到这一点!

这是主要的GUI __init__

class GUI(wx.Frame):
    #GUI
    def __init__(self, parent, id, title):
        self.inv = GetInvent()
        self.inv.Login()
        self.packages = self.inv.getinv()
        self.packages2 = self.inv.getSDB()
        self.id_list = self.inv.id_list

        self.show = 1

        wx.Frame.__init__(self, parent, id, title, size=(450, 400))

1 个答案:

答案 0 :(得分:1)

尝试以下代码。替换__init__签名以使参数可选,除了parent,title:

def __init__(self, parent, title, *args, **kwargs):
        super(Action, self).__init__(parent, title=title, size=(200, 200))
        self.InitUI()    
        self.Centre()
        self.Show()