There are other people that should be doing this - but I guess I'll dispense my little knowledge of this, and then let other people correct me. =)

Windows are the main thing in a GUI (duh!). In wxWidgets, almost all windows need to have a wxFrame as a parent - for sure, you will have one wxFrame for your application.

For me, the part that took me the longest to figure out, and what really isn't in the documentation, is a good way to size your window to the frame. So:

Sizing Windows

This snippet of code should help you to size the window according to the parent (and the parent is probably a wxFrame). It assumes, of course, that the parent has a defined size:

   1 class MyWindow (wxWindow):
   2    def __init___(self,parent):
   3       wxWindow.__init__(self, parent,-1)
   4       self.SetSize(parent.GetClientSize())

Yes, it's that easy. But what if your window isn't in a frame - like a pop-up window? Here's what I did for a wxDialog containing an wxHtmlWindow (I pretty much stole this from the demo that comes with wxPython):

   1 class MyInfo(wxDialog):
   2   htmlStr = "<html><body><h1>Your content here</h1></body></html>"
   3 
   4   #again, parent is a frame, though it won't appear "bounded" in a frame
   5   def __init__ (self,parent):  
   6      wxDialog.__init__(self,parent,-1, "About")
   7 
   8      # I found it's best to set either the width or the height
   9      self.htmlWin = wxHtmlWindow(self,-1,size=(300,-1))  
  10      self.htmlWin.SetPage(self.htmlStr)
  11 
  12      ir = self.htmlWin.GetInternalRepresentation()
  13      self.html.SetSize( (ir.GetWidth()+5, ir.GetHeight()+5) )
  14 
  15      self.SetClientSize(self.html.GetSize())
  16      self.CentreOnParent(wxBOTH)

wxSplitterWindow - Setting Relative Size

This section moved to ProportionalSplitterWindow.

Questions

WorkingWithWindows (last edited 2010-07-29 16:24:11 by fl-67-235-186-192)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.