python - wxPython wx.ScrolledWindow insert wx.Panel -
i trying insert wx.panel wx.scrolledwindow. have wx.panel object named self.enttitle have 2 input fields title , date. have few other objects want add in scrolledwindow, want 1 working first before go on others. here code:
main.py
import wx 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 notebook on panel self.nb = wx.notebook(self.main, 1) # create page windows children of notebook entrypg = entryscrollpanel(self.nb, wx.id_any, wx.defaultposition, wx.defaultsize, style=wx.vscroll) # add pages notebook label show on tab self.nb.addpage(self.userfcode, "fcodes") # create sizers self.mainsizer = wx.boxsizer(wx.vertical) # adding objects 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
import wx 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 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
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 error 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 add self.enttitle entryscrollpanel?
thank , help!
a panel not wxwindow that:
self.enttitle = titlepanel(wx.panel, -1)
doesn't work , produces traceback.
above code instantiating wx.panel subclass (titlepanel) , sending wx.panel parent constructor in:
class titlepanel(wx.panel): def __init__(self, parent, id): wx.panel.__init__(self, parent, id)
but panel needs window (p.e. frame) parent.
thus must instead:
self.enttitle = titlepanel(self, -1)
as self, here, parent of titlepanel, wx.scrolledwindow
also note did not initialized scrolledwindow:
class entryscrollpanel(wx.scrolledwindow): def __init__(self, parent, id): wx.scrolledwindow.__init__(self, parent, id) <--- addd
Comments
Post a Comment