Hello all,
I have been banging my head against the wall for days now trying to
figure out the why I can't get scrollbars to work. I have enclosed a
little program which shows what my problem is. It seems that if I add
objects to a BoxSizer, then set the sizer of MyWindow, I don't get the
scrollbar. But, if I don't use the BoxSizer for MyWindow, the
scrollbars appear.
If you run the enclosed pgm with no args, you get scrollbars. This is
is because you don't use the BoxSizer for MyWindow.
# ./broken.py
Running the pgm as follows will make the buttons imperceptible(I still
don't know why this is happening):
# ./broken.py -usebroken
Running the pgm as follows will make the buttons visible, but you
can't see the scrollbar:
# ./broken.py -usebroken -noscroll
I am sure it's something I am doing, I just don't know what.
Thanks,
Chuck
#!/usr/bin/env python
···
#
#
import sys
from wxPython.wx import *
DFL_WID = -1
use_broken = False
show_noscroll = False
class MyScroller( wxScrolledWindow ):
def __init__( self, parent, id ):
wxScrolledWindow.__init__( self, parent, id, style=wxVSCROLL )
self.SetScrollRate( 5, 5 )
mainLayout = wxBoxSizer( wxVERTICAL )
for i in range( 0, 100 ):
mainLayout.Add( wxButton( self, DFL_WID, 'Button' + str(i)) )
if show_noscroll:
self.SetAutoLayout( True )
self.SetSizerAndFit( mainLayout )
else:
self.SetSizer( mainLayout )
class MyWindow( wxFrame ):
def __init__( self, parent, id, title='MyWindow' ):
wxFrame.__init__( self, parent, id, title )
if use_broken:
frameLayout = wxBoxSizer( wxVERTICAL )
frameLayout.Add( MyScroller( self, DFL_WID ) )
self.SetSizer( frameLayout )
else:
scroll = MyScroller( self, DFL_WID )
self.Show( True )
if len( sys.argv ) >= 2:
for a in sys.argv:
if a == '-usebroken':
use_broken = True
elif a == '-noscroll':
show_noscroll = True
else:
continue
app = wxPySimpleApp()
frame = MyWindow( None, DFL_WID )
app.MainLoop()