ScrolledWindow that doesnt scroll

I have a wxScrolledWindow that I think should create scroll bars when
I resize it, or at least resize whats in it's sizer but it does not
seem to work

import wxversion
wxversion.select(["2.7"])
import wx

class form_panel(wx.ScrolledWindow):
    def __init__(self, parent):
        wx.ScrolledWindow.__init__(self, parent, wx.ID_ANY,
style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL)

        self.main_sizer = wx.BoxSizer(wx.VERTICAL)

        self.main_sizer.Add(listbox_panel(self), 0, wx.EXPAND)
        self.main_sizer.Add(wx.Size(10,10))

        self.SetSizer(self.main_sizer)
        self.SetAutoLayout(True)
        self.Fit()

class listbox_panel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY)

        opts = ['aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']
        self.list = wx.ComboBox(self,wx.ID_ANY, choices=opts,
style=wx.CB_READONLY)

        sizer = wx.BoxSizer(wx.HORIZONTAL)

        sizer.Add(wx.StaticText(self, wx.ID_ANY, "list box: "), 0, wx.EXPAND)
        sizer.Add(wx.Size(5,0))

        sizer.Add(self.list, 0, wx.EXPAND)

        sizer.Add(wx.Button(self, wx.ID_ANY, "Send"), 0, wx.EXPAND)

        self.sizer = sizer
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        self.Fit()

def main():
    app = wx.PySimpleApp()
    mywindow = wx.Frame(None, wx.ID_ANY, "Test Window")
    mywindow.panel = form_panel(mywindow)
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(mywindow.panel, 1, wx.EXPAND)

    mywindow.panel.main_sizer.Add(form_panel(mywindow), 0, wx.EXPAND)
    mywindow.panel.main_sizer.Add(wx.Size(10,10))

    mywindow.SetSizer(sizer)
    mywindow.SetAutoLayout(True)
    mywindow.Fit()
    mywindow.Show()
    app.MainLoop()

if __name__ == "__main__":
    main()

test.py (1.71 KB)

Don't use the wx.ScrolledWindow, it requires more to get working than
necessary. Use wx.ScrolledPanel instead and make sure to call its
.SetupScrolling() method before returning from .__init__() .

- Josiah

···

"Dj Gilcrease" <digitalxero@gmail.com> wrote:

I have a wxScrolledWindow that I think should create scroll bars when
I resize it, or at least resize whats in it's sizer but it does not
seem to work

> Don't use the wx.ScrolledWindow, it requires more to get working than
> necessary. Use wx.ScrolledPanel instead and make sure to call its
> .SetupScrolling() method before returning from .__init__() .
>
> - Josiah
>
>

While the ScrolledPanel does indeed draw the scrollbars, it does not
start with the window large enough to fit the ComboBox by default (I
can get Scrolled window to scroll with SetScrollbar but then it does
not size properly either). What I am looking for is a window that will
when first created is large enough to contain all of it's children
without scrolling (Provided enough screen width) and only if the user
shrinks the window should the scroll bars appear.

Don't call self.Fit() . From what I understand, self.Fit() calls the
.GetMinSize() methods of all widgets recursively, and sets the overall
window size to be the smallest it can possibly be. Remove that call,
and create your window with sufficient initial size to not require
scrollbars.

Also when I changed wx.ScrolledWindow to
wx.lib.scrolledpanel.ScrolledPanel the scrollbar of the child scrolled
window over drew the 2nd ComboBox

Without seeing screenshots or code I can't help you.

- Josiah

···

"Dj Gilcrease" <digitalxero@gmail.com> wrote:

On 11/12/06, Josiah Carlson <jcarlson@uci.edu> wrote: