[英]wxPython wx.ScrolledWindow insert wx.Panel
I am trying to insert a wx.Panel into a wx.ScrolledWindow. 我正在尝试将wx.Panel插入wx.ScrolledWindow。 I have a wx.Panel object named self.entTitle that have two input fields for Title and Date. 我有一个名为self.entTitle的wx.Panel对象,其中有两个输入字段分别是Title和Date。 I have a few other objects I want to add in the scrolledwindow, but I want to get this one working first before I go on to the others. 我想在滚动窗口中添加其他一些对象,但是在继续进行其他操作之前,我想先使该对象工作。 Here is my code: 这是我的代码:
main.py main.py
import wx
from EntryScrollPanel import EntryScrollPanel
class MyFrame(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title=title, size=(850,725))
# Creating Panels
self.main = wx.Panel(self)
# Create a notebook on the panel
self.nb = wx.Notebook(self.main, 1)
# create the page windows as children of the notebook
entryPg = EntryScrollPanel(self.nb, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, style=wx.VSCROLL)
# add the pages to the notebook with the label to show on the tab
self.nb.AddPage(self.userFCode, "FCodes")
# Create sizers
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
# Adding Objects to mainSizer
self.mainSizer.AddSpacer(10)
#self.mainSizer.Add(self.mainLogin, 1, wx.ALL|wx.EXPAND)
self.mainSizer.Add(self.nb, 1, wx.ALL|wx.EXPAND)
# Set main sizer
self.main.SetAutoLayout(True)
self.main.SetSizer(self.mainSizer)
self.mainSizer.Fit(self.main)
self.Layout()
self.Centre(wx.BOTH)
self.Show()
app = wx.App(False)
frame = MyFrame(None, -1, 'App UI')
app.MainLoop()
EntryScrollPanel.py EntryScrollPanel.py
import wx
from titlePanel import titlePanel
class EntryScrollPanel(wx.ScrolledWindow):
def __init__(self, parent, ID, pos, size, style):
#self.SetScrollRate( 5, 5 )
self.entryPgBox = wx.BoxSizer(wx.VERTICAL)
#self.entTitle = titlePanel(self, -1) i've tried this as well with no success
self.entTitle = titlePanel(wx.Panel, -1)
self.entryPgBox.AddSpacer(10)
self.entryPgBox.Add(self.entTitle, 0, wx.EXPAND)
self.entryPgBox.AddSpacer(10)
self.SetAutoLayout(True)
self.SetSizer(self.entryPgBox)
self.entryPgBox.Fit(self)
titlePanel.py titlePanel.py
import wx
class titlePanel(wx.Panel):
def __init__(self, parent, ID):
wx.Panel.__init__(self, parent, ID)
titleSizer = wx.BoxSizer(wx.HORIZONTAL)
titleLbl = wx.StaticText(self, label="Title: ")
titleTxt = wx.TextCtrl(self, size=(140,-1))
dateLbl = wx.StaticText(self, label="Date: ")
dateCal = wx.DatePickerCtrl(self, wx.DP_DROPDOWN)
titleSizer.Add(titleLbl,0,wx.EXPAND)
titleSizer.Add(titleTxt,1,wx.EXPAND)
titleSizer.Add(dateLbl,0,wx.EXPAND)
titleSizer.Add(dateCal,0,wx.EXPAND)
This is the error I get: 这是我得到的错误:
Traceback (most recent call last):
File "C:/Users/JLP_COM1/PycharmProjects/wxPython/wxPythonHelloWorld.py", line 283, in <module>
frame = MyFrame(None, -1, 'Small editor')
File "C:/Users/JLP_COM1/PycharmProjects/wxPython/wxPythonHelloWorld.py", line 71, in __init__
entryPg = EntryScrollPanel(self.nb, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, style=wx.VSCROLL)
File "C:\Users\JLP_COM1\PycharmProjects\wxPython\EntryScrollPanel.py", line 17, in __init__
self.entTitle = titlePanel(self, -1)
File "C:\Users\JLP_COM1\PycharmProjects\wxPython\titlePanel.py", line 5, in __init__
wx.Panel.__init__(self, parent, ID)
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_windows.py", line 68, in __init__
_windows_.Panel_swiginit(self,_windows_.new_Panel(*args, **kwargs))
TypeError: in method 'new_Panel', expected argument 1 of type 'wxWindow *'
How do I add self.entTitle to EntryScrollPanel? 如何将self.entTitle添加到EntryScrollPanel?
Thank you for any and all help! 感谢您提供的所有帮助!
A Panel is not an wxWindow so that: 面板不是wxWindow,因此:
self.entTitle = titlePanel(wx.Panel, -1)
doesn't work and produces the traceback. 不起作用并产生回溯。
The above code is instantiating an wx.Panel subclass (titlePanel) and sending an wx.Panel as the parent for its constructor in: 上面的代码实例化了wx.Panel子类(titlePanel),并在以下位置将wx.Panel作为其构造函数的父级发送:
class titlePanel(wx.Panel):
def __init__(self, parent, ID):
wx.Panel.__init__(self, parent, ID)
but a Panel needs a window (pe a Frame) as parent. 但是面板需要一个窗口(pe框架)作为父窗口。
Thus you must do instead: 因此,您必须改为:
self.entTitle = titlePanel(self, -1)
as self, here, the parent of TitlePanel, is a wx.ScrolledWindow 作为自身,这里是TitlePanel的父级,是wx.ScrolledWindow
Also note you did not initialized your ScrolledWindow: 还要注意,您没有初始化ScrolledWindow:
class EntryScrollPanel(wx.ScrolledWindow):
def __init__(self, parent, ID):
wx.ScrolledWindow.__init__(self, parent, ID) <--- addd this
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.