I'm looking into wxPython as a new GUI toolkit to port an application I
have written in Perl/Tk. I'm pretty comfortable with the Perl/Tk way of
doing things, which I think is causing me some mental blocks as I attempt
to use wxPython.
One of the things that's giving me the most grief are the box sizers. I'm
attaching a reduced testcase, which in my mind should lay things out as is
drawn up in the comments of the code. However, everything is placed at
the 0,0 coordinate (top-left corner of the frame). I think I'm still
stuck in the Tk "Pack" mode of thinking, expecting the wxBoxSizer to do
stuff that it's not set up to do.
I'm sure that this is a pretty simple conceptual thing that I'm just not
getting, so I'll be very grateful to the person who can explain to me what
I'm doing wrong.
Thanks,
Wade
##### CODE SAMPLE ####
#!/usr/bin/env python
import sys, os, string
from wxPython.wx import *
class main_window(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, -1, title, size = (-1, -1), style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
# Build the search area
# This should eventually look like
# +---------------------------------+
# | Label [wxChoice] |
# | |
# | +---------------------------+ |
# | | | |
# | | wxListBox | |
# | | | |
# | +---------------------------+ |
# | |
# +---------------------------------+
self.box = wxBoxSizer(wxVERTICAL)
self.searchareabox = wxBoxSizer(wxVERTICAL)
self.categorybox = wxBoxSizer(wxHORIZONTAL)
self.categorybox.Add(wxStaticText(self, -1, "Choose your category"),1,wxEXPAND)
self.categorybutton = wxChoice(self, 40, choices = [])
self.categorybox.Add(self.categorybutton,1,wxEXPAND)
self.searchareabox.Add(self.categorybox,1,wxEXPAND)
self.box.Add(self.searchareabox,1,wxEXPAND)
self.categorybutton.Append("Any Category","Any")
self.categorybutton.Append("Other Category","Other")
self.categorybutton.SetSelection(0)
self.mainbox = wxListBox(self, 60, (-1,-1), (-1,-1), [], wxLB_SINGLE)
self.searchareabox.Add(self.mainbox,1,wxEXPAND)
self.mainbox.Append("Test Data","Item 1")
self.mainbox.Append("Test Data 2","Item 2")
self.Show(true)
class App(wxApp):
def OnInit(self):
frame = main_window(None, -1, "Reduced Testcase")
self.SetTopWindow(frame)
return true
app = App(0)
app.MainLoop()