wxPython 需要给 StaticBox 添加滚动条;这可能吗?
wxPython need to add scrollbar to StaticBox; is this possible?
我见过类似的问题,但是 none 帮助我解决了我的具体问题。
我在 wx.Panel 上有一堆不同的 StaticBoxes。我动态地将 TextFields 添加到一个特定的 StaticBox。如果我添加太多,因为 BoxSizer 设置为 wx.VERTICAL(这是我想要的),面板会扩展到丑陋的外观。是否可以向 StaticBox 添加滚动条?我发现的唯一可滚动对象是 wx.Panel 和 wx.Window.
为什么不把 StaticBox
放在 ScrolledPanel
中?那会很完美。这是一个简单的例子:
import wx
import wx.lib.scrolledpanel as scrolled
########################################################################
class MyPanel(scrolled.ScrolledPanel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
super(MyPanel, self).__init__(parent,
style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
self.SetupScrolling()
box = wx.StaticBox(self, label="Test Box")
bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
for i in range(15):
txt = wx.TextCtrl(self)
bsizer.Add(txt, 0, wx.ALL, 5)
main_sizer = wx.BoxSizer()
main_sizer.Add(bsizer, 1, wx.EXPAND)
self.SetSizer(main_sizer)
########################################################################
class MainFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
super(MainFrame, self).__init__(None, title="Static")
panel = MyPanel(self)
self.Show()
if __name__ == '__main__':
app = wx.App(False)
frame = MainFrame()
app.MainLoop()
您可以使用顶级面板,然后将左侧面板和右侧面板作为子面板添加到顶部面板,其中右侧面板将是滚动面板实例。那将是一种有效的方法。
我见过类似的问题,但是 none 帮助我解决了我的具体问题。
我在 wx.Panel 上有一堆不同的 StaticBoxes。我动态地将 TextFields 添加到一个特定的 StaticBox。如果我添加太多,因为 BoxSizer 设置为 wx.VERTICAL(这是我想要的),面板会扩展到丑陋的外观。是否可以向 StaticBox 添加滚动条?我发现的唯一可滚动对象是 wx.Panel 和 wx.Window.
为什么不把 StaticBox
放在 ScrolledPanel
中?那会很完美。这是一个简单的例子:
import wx
import wx.lib.scrolledpanel as scrolled
########################################################################
class MyPanel(scrolled.ScrolledPanel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
super(MyPanel, self).__init__(parent,
style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
self.SetupScrolling()
box = wx.StaticBox(self, label="Test Box")
bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
for i in range(15):
txt = wx.TextCtrl(self)
bsizer.Add(txt, 0, wx.ALL, 5)
main_sizer = wx.BoxSizer()
main_sizer.Add(bsizer, 1, wx.EXPAND)
self.SetSizer(main_sizer)
########################################################################
class MainFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
super(MainFrame, self).__init__(None, title="Static")
panel = MyPanel(self)
self.Show()
if __name__ == '__main__':
app = wx.App(False)
frame = MainFrame()
app.MainLoop()
您可以使用顶级面板,然后将左侧面板和右侧面板作为子面板添加到顶部面板,其中右侧面板将是滚动面板实例。那将是一种有效的方法。