python - wxpython: issue with layout in example -
i trying learn wxpython , problem when run example code wiki:
the main frame isn't resizing properly. what's missing?
i running under enthought python distribution 7.3-2 (python 2.7.3)
# http://wiki.wxpython.org/getting%20started import wx class examplepanel(wx.panel): def __init__(self, parent): wx.panel.__init__(self, parent) # create sizers mainsizer = wx.boxsizer(wx.vertical) grid = wx.gridbagsizer(hgap=5, vgap=5) hsizer = wx.boxsizer(wx.horizontal) self.quote = wx.statictext(self, label="your quote: ") grid.add(self.quote, pos=(0,0)) # multiline textctrl - here show how events work in program, don't pay attention self.logger = wx.textctrl(self, size=(200,300), style=wx.te_multiline | wx.te_readonly) # button self.button =wx.button(self, label="save") self.bind(wx.evt_button, self.onclick,self.button) # edit control - 1 line version. self.lblname = wx.statictext(self, label="your name :") grid.add(self.lblname, pos=(1,0)) self.editname = wx.textctrl(self, value="enter here name", size=(140,-1)) grid.add(self.editname, pos=(1,1)) self.bind(wx.evt_text, self.evttext, self.editname) self.bind(wx.evt_char, self.evtchar, self.editname) # combobox control self.samplelist = ['friends', 'advertising', 'web search', 'yellow pages'] self.lblhear = wx.statictext(self, label="how did hear ?") grid.add(self.lblhear, pos=(3,0)) self.edithear = wx.combobox(self, size=(95, -1), choices=self.samplelist, style=wx.cb_dropdown) grid.add(self.edithear, pos=(3,1)) self.bind(wx.evt_combobox, self.evtcombobox, self.edithear) self.bind(wx.evt_text, self.evttext,self.edithear) # add spacer sizer grid.add((10, 40), pos=(2,0)) # checkbox self.insure = wx.checkbox(self, label="do want insured shipment ?") grid.add(self.insure, pos=(4,0), span=(1,2), flag=wx.bottom, border=5) self.bind(wx.evt_checkbox, self.evtcheckbox, self.insure) # radio boxes radiolist = ['blue', 'red', 'yellow', 'orange', 'green', 'purple', 'navy blue', 'black', 'gray'] rb = wx.radiobox(self, label="what color ?", pos=(20, 210), choices=radiolist, majordimension=3, style=wx.ra_specify_cols) grid.add(rb, pos=(5,0), span=(1,2)) self.bind(wx.evt_radiobox, self.evtradiobox, rb) hsizer.add(grid, 0, wx.all, 5) hsizer.add(self.logger) mainsizer.add(hsizer, 0, wx.all, 5) mainsizer.add(self.button, 0, wx.center) self.setsizerandfit(mainsizer) def evtradiobox(self, event): self.logger.appendtext('evtradiobox: %d\n' % event.getint()) def evtcombobox(self, event): self.logger.appendtext('evtcombobox: %s\n' % event.getstring()) def onclick(self,event): self.logger.appendtext(" click on object id %d\n" %event.getid()) def evttext(self, event): self.logger.appendtext('evttext: %s\n' % event.getstring()) def evtchar(self, event): self.logger.appendtext('evtchar: %d\n' % event.getkeycode()) event.skip() def evtcheckbox(self, event): self.logger.appendtext('evtcheckbox: %d\n' % event.checked()) app = wx.app(false) frame = wx.frame(none) panel = examplepanel(frame) frame.show() app.mainloop()
aha, figured out. call of frame.fit() missing before frame.show().
instead of
app = wx.app(false) frame = wx.frame(none) panel = examplepanel(frame) frame.show() app.mainloop()
it should be
app = wx.app(false) frame = wx.frame(none) panel = examplepanel(frame) frame.fit() frame.show() app.mainloop()
Comments
Post a Comment