Question

I am working with wxPython v3.0 and python v2.7 on Windows 8 OS. The code is provided below.

Problem: If you scroll the vertical scroll bar completely to the bottom and scroll the horizontal scroll bar completely to the right side, then you shall notice empty spaces at the bottom of the panels and at the right side of the panels as shown in the image below. How to avoid this? Is this the default behavior or am I doing something wrong? It would be great if someone can test this on his/her system and confirm if this is a normal behavior?

image

Code:

import wx
import wx.lib.scrolledpanel

class GUI(wx.Frame):
    def __init__(self, parent, id, title):
        screenWidth = 700
        screenHeight = 400
        screenSize = (screenWidth, screenHeight)
        wx.Frame.__init__(self, None, id, title, size=screenSize)
        myFont = wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD)
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        panelsSizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer1 = wx.BoxSizer(wx.VERTICAL)
        sizer2 = wx.BoxSizer(wx.VERTICAL)
        mainPanel = wx.lib.scrolledpanel.ScrolledPanel(self, -1,style=wx.SIMPLE_BORDER)
        mainPanel.SetupScrolling()
        panel1 = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER)
        panel1.SetupScrolling(scroll_y=False)
        panel2 = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER)
        panel1.SetBackgroundColour('#cccFFF')
        panel2.SetBackgroundColour('#FFFaaa')
        panelsSizer.Add(panel1, 1, wx.ALL|wx.EXPAND)
        panelsSizer.Add(panel2, 2, wx.ALL|wx.EXPAND)
        mainPanel.SetSizer(panelsSizer)

        k = 0
        #Populating the panel-1 with panels to show scroll bars
        for i in range(1,20):
            lPanels = 'lPanel'+str(k)
            lPanels = wx.Panel(panel1)
            label0 = str(k+1)+ '. '+'Panel-1   #############################'
            text0 = wx.StaticText(lPanels, -1, label0)
            text0.SetFont(myFont)
            sizer1.Add(lPanels, 0, wx.ALL|wx.EXPAND, 5)
            sizer1.Add(wx.StaticLine(panel1), 0, wx.ALL|wx.EXPAND, 0)
            k += 1

        k = 0
        #Populating the panel-2 with panels to show the scroll bars
        for i in range(1,20):
            sPanel ='sPanel' +str(k)
            sPanel = wx.Panel(panel2)
            label = str(k)+ '. Panel-2#############################'
            text = wx.StaticText(sPanel, -1, label)
            text.SetFont(myFont)
            sizer2.Add(sPanel, 0, wx.ALL|wx.EXPAND, 5)
            sizer2.Add(wx.StaticLine(panel2), 0, wx.ALL|wx.EXPAND, 0)
            k += 1

        panel1.SetSizer(sizer1)
        panel2.SetSizer(sizer2)
        mainSizer.Add(mainPanel, 15, wx.EXPAND|wx.ALL)
        self.SetSizer(mainSizer)

if __name__=='__main__':
    app = wx.App()
    frame = GUI(parent=None, id=-1, title="Test")
    frame.Show()
    app.MainLoop()

Thank you for your time!

Was it helpful?

Solution

It is normal. wx.ScrolledWindow rounds the virtual size up to the next multiple of the scroll rate, so you end up with between 0 and scroll rate extra pixels.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top