mubuyanzi 2019-11-11 11:31 采纳率: 50%
浏览 4179

python报错:__init__() missing 1 required positional argument: 'parent'

在python3的环境下使用wxpython进行程序编写,运行后出现报错:
init() missing 1 required positional argument: 'parent'
问题:parent值应该赋予什么
程序部分如下:

# 构建表格
class GridFrame(wx.grid.Grid):
    def __init__(self, parent):
        wx.grid.Grid.__init__(self, parent, -1)

        # grid = wx.grid.Grid(self, -1)
        self.CreateGrid(14, 14)
        n = 0
        m = 0
        while n <= 13:
            self.SetColSize(col=n, width=80)
            n = n + 1
            # print(n)
        else:
            print('Finished col')
        while m <= 13:
            self.SetRowSize(m, 30)
            m = m + 1
            # print(m)
        else:
            print('Finished row')

        self.SetCellValue(0, 0, 'Data')
        self.SetCellTextColour(0, 0, wx.BLACK)
        self.SetCellBackgroundColour(0, 0, wx.LIGHT_GREY)

        a = 1
        b = 6
        while a <= 7:
            while b >= 0:
                self.SetCellValue(a, 0, 'Z' + str(b))
                self.SetCellTextColour(a, 0, wx.BLACK)
                self.SetCellBackgroundColour(a, 0, wx.LIGHT_GREY)
                b = b - 1
                a = a + 1
                # print('Z' + str(b))
                # print(a)
        c = 8
        d = 1
        while c <= 13:
            while d <= 6:
                self.SetCellValue(c, 0, '-Z' + str(d))
                self.SetCellTextColour(c, 0, wx.RED)
                self.SetCellBackgroundColour(c, 0, wx.LIGHT_GREY)
                d = d + 1
                c = c + 1
                # print('Z' + str(d))
                # print(c)
        e = 1
        f = 0
        while e <= 12:
            while f <= 11:
                self.SetCellValue(0, e, str(30 * f) + '°')
                self.SetCellTextColour(0, e, wx.BLUE)
                self.SetCellBackgroundColour(0, e, wx.LIGHT_GREY)
                e = e + 1
                f = f + 1
        self.SetCellValue(0, 13, 'B0')
        self.SetCellTextColour(0, 13, wx.RED)
        self.SetCellBackgroundColour(0, 13, wx.LIGHT_GREY)
    # 主窗口部分构建
class TestFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, 'Guass_Measurement', size=(1250, 600),style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER | wx.MAXIMIZE_BOX)
        panel = wx.Panel(self, -1)
        ##############################################
        # 按钮设置
        ###############################################
        v_sizer = wx.BoxSizer(wx.HORIZONTAL)        
        self.outputdatabutton = wx.Button(panel, -1, u'导出Excel')
        self.Bind(wx.EVT_BUTTON, self.OnoutputdataCH, self.outputdatabutton)
        ###########################################
        # 静态文本框及下拉表单设置
        ###########################################
        h_sizer = wx.BoxSizer(wx.HORIZONTAL)
                ……
        ########################################
        # 加入表格后的整体布局设置
        ########################################
        grid = GridFrame(panel)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(v_sizer, proportion=0, flag=wx.EXPAND)
        sizer.Add(h_sizer, proportion=0, flag=wx.EXPAND)
        sizer.Add(grid, proportion=1, flag=wx.EXPAND, border=5)
        panel.SetSizer(sizer)
    #这是一个按钮的响应函数,想要从表格中获取数据并导出成Excel表格
    def OnoutputdataCH(self, event):
      for k in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]:
       for l in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]:
        w = GridFrame().GetCellValue(k, l)# 报错语句


class MyApp(wx.App):
    def OnInit(self):
        print("MyApp OnInit")
        self.frame = TestFrame(None)
        id = self.frame.GetId()
        self.frame.Show(True)
        return True

    def OnExit(self):
        print("MyApp OnExit")
        SerialFrame().close()
        time.sleep(2)


if __name__ == "__main__":
    "Main Start"
    app = MyApp()
    "Before MainLoop"
    # frame = TestFrame(None)
    # frame.Show(True)
    app.MainLoop()
    "After MainLoop"

求问大神应该怎么改?

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2019-11-11 11:40
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog