[wxPython] An Oddity

The script below behaves more or less as one
would expect, when the frame is resized.

However, if either of the commented lines
is uncommented, then the scroll bars remain,
no matter how large the frame is.

I say more or less because the scroll bars appear
even when the frame size exceeds the grid size
by perhaps 80 pixels in each dimension.

Is there some basic error in the code below?

Colin W.

from wxPython.wx import *
from wxPython.grid import *

class MyFrame(wxFrame):
    def __init__(self,parent,id,title):

        wxFrame.__init__(self,parent,id,title,wxPoint(-1,-1),(635,250))
# panel= wxPanel(self, -1)
        grid = wxGrid(self,-1, wxPoint(40, 40), wxSize(530, 200))
        grid.CreateGrid(5,5)
# EVT_SIZE(self, self.OnSize)

    def OnSize(self, event):
        print 'Frame Size:', event.GetSize()

class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame(None,-1,"wxGrid")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

app = MyApp(0)
app.MainLoop()

The script below behaves more or less as one
would expect, when the frame is resized.

However, if either of the commented lines
is uncommented, then the scroll bars remain,
no matter how large the frame is.

If the the wxFrame has only one child window it will automatically resize
that child to fill all the client area of the frame, so long as you don't
prevent the frame from getting the EVT_SIZE event since that is where it
does this sizing. So what you are seeing is two cases of disabling this
built-in behavioiur, adding a second child to the frame in the first case,
and catching the EVT_SIZE event in the second case. When that sizing
behaviour is turned off then the grid stays the same size and so the
scrollbars stay.

I say more or less because the scroll bars appear
even when the frame size exceeds the grid size
by perhaps 80 pixels in each dimension.

The grid has a margin to the right and bottom by default. You can change it
with grid.SetMargins(0,0)

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!