In my wxPython 4.1.0 app I inherit from wx.Frame
, then create a main panel from wx.Panel
, add a ScrolledPanel
and to that I add a wx.Bitmap
as child. That bitmap/image is larger in height than the scrolled panel, so the vertical scroll bar is shown - everything as expected.
Then I add another wx.Panel
below that scrolled panel, without any children, but that alone makes the scroll bar in the scrolled panel disappear. Is this a bug or a feature?
Here is a fully working example.
Uncomment the code in def init_panel(self)
to see the strange behaviour:
import wx
import wx.grid
import wx.lib.intctrl
import wx.lib.scrolledpanel
class TestApp(wx.Frame):
IMAGE_SIZE = 800
SCROLL_SPEED = 10
def __init__(self):
super(TestApp, self).__init__(
None, title="wxPython Test", style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER,
)
self.init_panel()
self.main_panel.Layout()
self.main_panel.Fit()
self.Center()
self.Show()
def init_panel(self):
self.main_panel = wx.Panel(self)
self.main_sizer = wx.BoxSizer(wx.VERTICAL)
self.main_panel.SetSizer(self.main_sizer)
self.bitmaps_panel = wx.lib.scrolledpanel.ScrolledPanel(self.main_panel)
self.bitmaps_panel.SetMinSize((-1, 250))
self.bitmaps_panel.SetupScrolling(scroll_x=False, scroll_y=True, rate_y=self.SCROLL_SPEED)
self.bitmaps_panel.SetAutoLayout(True)
self.bitmaps_sizer = wx.BoxSizer(wx.VERTICAL)
self.bitmaps_panel.SetSizer(self.bitmaps_sizer)
bitmap = wx.Bitmap(wx.Image(self.IMAGE_SIZE, self.IMAGE_SIZE))
self.bitmaps_sizer.Add(wx.StaticBitmap(self.bitmaps_panel, wx.ID_ANY, bitmap))
self.bitmaps_sizer.Fit(self)
self.main_sizer.Add(self.bitmaps_panel, 0, flag=wx.EXPAND)
## With this block commented it works, uncomment to see the scroll bar dissapear
# self.stats_panel = wx.Panel(self)
# self.stats_sizer = wx.BoxSizer(wx.VERTICAL)
# self.stats_panel.SetSizer(self.stats_sizer)
# self.main_sizer.Add(self.stats_panel, 0, flag=wx.EXPAND)
self.main_sizer.Fit(self)
if __name__ == "__main__":
wxapp = wx.App()
app = TestApp()
wxapp.MainLoop()
Might this quirk not be explained by your creating stats_panel
as a child of self
, rather than self.main_panel
?
import wx
import wx.grid
import wx.lib.intctrl
import wx.lib.scrolledpanel
class TestApp(wx.Frame):
IMAGE_SIZE = 800
SCROLL_SPEED = 10
def __init__(self):
super(TestApp, self).__init__(
None, title="wxPython Test", style=wx.DEFAULT_FRAME_STYLE)
self.init_panel()
self.main_panel.Layout()
self.main_panel.Fit()
self.Center()
self.Show()
def init_panel(self):
self.main_panel = wx.Panel(self)
self.bitmaps_panel = wx.lib.scrolledpanel.ScrolledPanel(self.main_panel)
self.bitmaps_panel.SetMinSize((-1, 250))
self.bitmaps_panel.SetupScrolling(scroll_x=True, scroll_y=True, rate_y=self.SCROLL_SPEED)
self.bitmaps_panel.SetAutoLayout(True)
bitmap = wx.Bitmap(wx.Image(2000, self.IMAGE_SIZE))
self.bitmap = wx.StaticBitmap(self.bitmaps_panel, wx.ID_ANY, bitmap)
self.stats_panel = wx.Panel(self.main_panel)
self.stats_panel.SetBackgroundColour('lightblue')
label = wx.StaticText(self.stats_panel, label="Stats Panel")
self.bitmaps_sizer = wx.BoxSizer(wx.VERTICAL)
self.bitmaps_sizer.Add(self.bitmap, 0, wx.EXPAND, 5)
self.bitmaps_panel.SetSizer(self.bitmaps_sizer)
self.stats_sizer = wx.BoxSizer(wx.VERTICAL)
self.stats_sizer.Add(label)
self.stats_panel.SetSizer(self.stats_sizer)
self.main_sizer = wx.BoxSizer(wx.VERTICAL)
self.main_sizer.Add(self.bitmaps_panel, 0, flag=wx.EXPAND)
self.main_sizer.Add(self.stats_panel, 1, flag=wx.EXPAND)
self.main_panel.SetSizer(self.main_sizer)
if __name__ == "__main__":
wxapp = wx.App()
app = TestApp()
wxapp.MainLoop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.