在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"
求问大神应该怎么改?