Help getting a scrolled page in a wx.Listbook

28 views
Skip to first unread message

Ryan Holmes

unread,
Feb 19, 2018, 1:48:07 AM2/19/18
to wxPython-users

Using Python 3.6, wxPython 4.0.1

I have the following code:

import wx

class MyDialog(wx.Frame):
   
def __init__(self, parent):
        wx
.Frame.__init__(self, parent, id=wx.ID_ANY, size=wx.DefaultSize)
        mainSizer
= wx.BoxSizer(wx.VERTICAL)

       
self.listbook = wx.Listbook(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LB_DEFAULT)
        mainSizer
.Add(self.listbook, 1, wx.EXPAND)

        page
= MyPage(self.listbook)
       
self.listbook.AddPage(page, "Test")

       
self.SetSizer(mainSizer)
       
self.Centre(wx.BOTH)
       
self.Layout()

class MyPage(wx.ScrolledWindow):
   
def __init__(self, parent):
        wx
.ScrolledWindow.__init__(self, parent)

        mainSizer
= wx.BoxSizer(wx.VERTICAL)

       
for x in range(20):
            setattr
(self, "test{}".format(x), wx.CheckBox(self, wx.ID_ANY, "Test Content {}".format(x),
            wx
.DefaultPosition, wx.DefaultSize, 0))
            mainSizer
.Add(getattr(self, "test{}".format(x)), 0, wx.ALL | wx.EXPAND, 5)

       
self.SetSizer(mainSizer)
       
self.Layout()

if __name__ == "__main__":
    app
= wx.App()
    frame
= MyDialog(None)
    frame
.Show()
    app
.MainLoop()

It's pretty basic boilerplate code that creates a Listbook, adds a page, and generates controls within that page (20 of them). Here's an image of what this code does:

Ryan Holmes

unread,
Feb 19, 2018, 1:49:42 AM2/19/18
to wxPython-users
Seems google got confused when I inserted the image and posted it at the top as well! Whoops :)

Tim Roberts

unread,
Feb 19, 2018, 1:27:04 PM2/19/18
to wxpytho...@googlegroups.com
Ryan Holmes wrote:
>
> It's pretty basic boilerplate code that creates a Listbook, adds a
> page, and generates controls within that page (20 of them). Here's an
> image of what this code does:
> ...
> As you can see, it defaults to only showing the first 7 (and a little
> more some) controls, when there are 20, without any scroll.  The user
> would have to resize the entire window in order to see all the
> content.  I've tried a few different way, with no luck.  How can I
> accomplish this?

Accomplish what?  You've done a very nice job of coming up with a
minimal test case and describing what the code actually does, but you
haven't told us what behavior you WANT.

I'm guessing you want to see a vertical scrollbars in the content
window.  In that case, you have to provide the scrolling hints.  Add:
        self.SetScrollbars( 1, 1, 20, 20 )
and I think you'll be happier.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Ryan Holmes

unread,
Feb 19, 2018, 8:43:23 PM2/19/18
to wxPython-users
Ah, thank you! Yeah, re-reading it I can see I never actually came to what exactly I wanted lol

But thanks, that code works great for what I'm wanting, and it's so simple!
Reply all
Reply to author
Forward
0 new messages