将 wxpython 面板类添加到 sizers
我想将面板类添加到框架类中的 sizer,我将在代码的主行中调用该框架类。
我得到的错误是TypeError: wx.Window, wx.Sizer, wx.Size, or (w,h) Expected for item
。我认为这与它是面板类而不是面板类的实例有关。
无论哪种方式,我将如何做这样的事情?
代码如下:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class step_1(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, id=wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
txtOne = wx.TextCtrl(self, wx.ID_ANY, "")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(txtOne, 0, wx.ALL, 5)
self.SetSizer(sizer)
class step_2(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, id=wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
txtOne = wx.TextCtrl(self, wx.ID_ANY, "")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(txtOne, 0, wx.ALL, 5)
self.SetSizer(sizer)
class main_frame(wx.Frame):
"""Main Frame holding the main panel."""
def __init__(self,*args,**kwargs):
wx.Frame.__init__(self,*args,**kwargs)
p = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(step_1,0,border = 5)
sizer.Add(step_2,0,border = 5)
p.SetSizerAndFit(sizer)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = main_frame(None,-1,size = (400,300))
app.MainLoop()
I want to add panel classes to a sizer in a frame class that I will call in the main line of the code.
The error I get is TypeError: wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item
. I assume this has to do with the fact that it is a panel class and not the instance of the panel class..
Either way, how would I do such a thing?
Code is below:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class step_1(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, id=wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
txtOne = wx.TextCtrl(self, wx.ID_ANY, "")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(txtOne, 0, wx.ALL, 5)
self.SetSizer(sizer)
class step_2(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, id=wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
txtOne = wx.TextCtrl(self, wx.ID_ANY, "")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(txtOne, 0, wx.ALL, 5)
self.SetSizer(sizer)
class main_frame(wx.Frame):
"""Main Frame holding the main panel."""
def __init__(self,*args,**kwargs):
wx.Frame.__init__(self,*args,**kwargs)
p = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(step_1,0,border = 5)
sizer.Add(step_2,0,border = 5)
p.SetSizerAndFit(sizer)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = main_frame(None,-1,size = (400,300))
app.MainLoop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像您自己所说:您没有将
step_1
和step_2
类的实例传递给 sizer,当然您应该这样做。只需创建它们的实例:Like you said yourself: You're not passing instances of the
step_1
andstep_2
classes to the sizer, which of course you should be. Simply create instances of them: