我想要一个垂直滚动条遍布框架(Top Block)。我可以为各个面板获取垂直滚动条 -
以下是在 gnuradio 中设置top block
的代码 -
class top_block_gui(gr.top_block):
def __init__(self, title='', size=default_gui_size):
gr.top_block.__init__(self)
.............
self._frame = wx.Frame(None, title=title)
self._panel = panel.Panel(self._frame)
.............
def Run(self, start=True, max_nouts=0):
#setup app
self._frame.Bind(wx.EVT_CLOSE, _quit)
self._sizer = wx.BoxSizer(wx.VERTICAL)
self._sizer.Add(self._panel, 0, wx.EXPAND)
self._frame.SetSizerAndFit(self._sizer)
self._frame.SetAutoLayout(True)
self._frame.Show(True)
self._app.SetTopWindow(self._frame)
#start flow graph
..................
修改1 - 按 pss
中的方法1 中的建议 -class top_block_gui(gr.top_block):
def __init__(self, title='', size=default_gui_size):
gr.top_block.__init__(self)
.............
self._frame = wx.Frame(None, title=title)
self._scroll = wx.ScrolledWindow(self._frame,-1) #Added
self._scroll.SetScrollbars(1,1,600,400) #Added
self._panel = panel.Panel(self._scroll) #Changed
.............
def Run(self, start=True, max_nouts=0):
#setup app
self._frame.Bind(wx.EVT_CLOSE, _quit)
self._sizer = wx.BoxSizer(wx.VERTICAL)
self._sizer.Add(self._panel, 0, wx.EXPAND)
self._scroll.SetSizerAndFit(self._sizer) #Changed
self._frame.SetAutoLayout(True)
self._frame.Show(True)
self._app.SetTopWindow(self._frame)
#start flow graph
..................
但我仍然得到与以前相同的结果。 不显示滚动条。我是否必须在任何地方将可见性设置为?
答案 0 :(得分:1)
您可以使用以下任一方法:
方法1:您可以使用wx.ScrolledWindow
示例代码:
import wx
import wx.lib.scrolledpanel
class GUI(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Test app v1.0", style = wx.DEFAULT_FRAME_STYLE )
self.Center()
self.CreateStatusBar()
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.scroll = wx.ScrolledWindow(self, -1)
self.scroll.SetScrollbars(1, 1, 600, 400)
panelA = wx.lib.scrolledpanel.ScrolledPanel(self.scroll, -1, style=wx.SIMPLE_BORDER, size=(300,200))
panelA.SetupScrolling()
panelA.SetBackgroundColour('#EEE111')
panelB = wx.lib.scrolledpanel.ScrolledPanel(self.scroll, -1, style=wx.SIMPLE_BORDER, size=(200,200))
panelB.SetupScrolling()
panelB.SetBackgroundColour('#Eaa222')
mainSizer.Add(panelA, 1, wx.ALL|wx.EXPAND, 5)
mainSizer.Add(panelB, 1, wx.ALL|wx.EXPAND, 5)
self.scroll.SetSizer(mainSizer)
if __name__=='__main__':
app = wx.App(0)
frame = GUI().Show()
app.MainLoop()
方法2:您可以使用wx.lib.scrolledpanel.ScrolledPanel
示例:
import wx
import wx.lib.scrolledpanel
class GUI(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Test app v1.0", style = wx.DEFAULT_FRAME_STYLE )
self.Center()
self.CreateStatusBar()
mainSizer = wx.BoxSizer(wx.VERTICAL)
mainPanel = wx.lib.scrolledpanel.ScrolledPanel(self, -1, style=wx.SIMPLE_BORDER, size=(400, 200))
mainPanel.SetupScrolling()
mainPanel.SetBackgroundColour('#00000')
panelA = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER, size=(300,200))
panelA.SetupScrolling()
panelA.SetBackgroundColour('#EEE111')
panelB = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER, size=(200,200))
panelB.SetupScrolling()
panelB.SetBackgroundColour('#Eaa222')
mainSizer.Add(panelA, 1, wx.ALL|wx.EXPAND, 5)
mainSizer.Add(panelB, 1, wx.ALL|wx.EXPAND, 5)
mainPanel.SetSizer(mainSizer)
if __name__=='__main__':
app = wx.App(0)
frame = GUI().Show()
app.MainLoop()
<强>输出强>: