gpt4 book ai didi

python - 将垂直滚动条添加到跨多个面板的 wxFrame

转载 作者:太空宇宙 更新时间:2023-11-03 17:39:17 24 4
gpt4 key购买 nike

我想要一个垂直滚动条贯穿框架(顶部 block )。我能够获得各个面板的垂直滚动条 -

Top Block

这里的两个图都是 threads由相同的 class 绘制.

这是在gnuradio中设置顶部 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
..................

但我仍然得到与以前相同的结果。 不出现滚动条。我是否必须在某个地方将其可见性设置为 true

最佳答案

您可以使用以下任一方法来执行此操作:

方法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()

输出:

Code output

关于python - 将垂直滚动条添加到跨多个面板的 wxFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30797443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com