problem with wxPanel derivation class
kyosohma at gmail.com
kyosohma at gmail.com
Thu Oct 11 16:35:49 EDT 2007
You've got calls for properties in other classes and you don't
initialize the panel object. I edited the code somewhat so it'll at
least run. I tried to comment where I changed things, but I may have
missed a few minor points. See below:
<code>
#The commented out code from MyFrame was moved to class Panel \
# and appropriately modified by changing self.panel to self etc
import wx
class MyFrameTwo(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrameTwo.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
## self.panel = panel(self, -1)
self.panel = Panel(self, -1)
self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrameTwo.__set_properties
self.SetTitle("frame_1")
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrameTwo.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.panel, 1, wx.EXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
sizer_1.SetSizeHints(self)
self.Layout()
# end wxGlade
# end of class MyFrameTwo
class Panel (wx.Panel):
def __init__(self, parent, *args, **kwds):
wx.Panel.__init__(self, parent) # Added line
self.staticbox = wx.StaticBox(self, -1, "StaticBox")
self.label = wx.StaticText(self, -1, "Field Name")
self.textBox = wx.TextCtrl(self, -1, "Field Value")
self.button = wx.Button(self, -1, "Edit")
self.__doLayout() # added self
def __doLayout(self): # added argument
sizer = wx.StaticBoxSizer(self.staticbox,
wx.HORIZONTAL)
sizer.Add(self.label, 0, wx.ALL, 3)
sizer.Add(self.textBox, 0, wx.ALL, 3)
sizer.Add(self.button, 0, wx.ALL, 3)
self.label.SetMinSize((-1, 15)) # moved from Frame
# maybe comment this and uncommennt frame2's
corresponding line
self.SetAutoLayout(True)
self.SetSizer(sizer)
sizer.Fit(self)
sizer.SetSizeHints(self)
## modified from BoaApp
class App(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
self.main = MyFrameTwo(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
application = App(0)
application.MainLoop()
if __name__ == '__main__':
main()
</code>
Larry is correct. You'll get better help from the wxPython group. See
http://wxpython.org/maillist.php
Mike
More information about the Python-list
mailing list