Add scrollbars in wxpython, but it doesn't appear

久未见 提交于 2019-12-11 04:25:26

问题


I saw a lot of scrollbars on the web, but my situation is different, with more wx.FlexGridSizer objects.The scoller dosen't appear.

 class MPL_Frame(wx.Frame):
    """MPL_Frame可以继承,并可修改,或者直接使用"""
    # global task
    def __init__(self, title="MPL_Frame Example In wxPython", size=(1300, 500)):
        wx.Frame.__init__(self, parent=None, title=title, size=size)
        self.scroller = wx.ScrolledWindow(self, -1)
        self.scroller.SetScrollbars(1, 1, 640, 400)
        self.grid = DataGrid(self, (17, 16))
        ship_grid = DataGrid(self, (10, 4))
        plane_grid = DataGrid(self, (10, 6))
        self.MPL = MPL_Panel_base(self)
        # self.MPL.Figure.canvas.mpl_connect('button_press_event', onClick)


        # 创建FlexGridSizer
        self.FlexGridSizer = wx.FlexGridSizer(rows=9, cols=0, vgap=5, hgap=5)
        self.FlexGridSizer.SetFlexibleDirection(wx.BOTH)

        self.RightPanel = wx.Panel(self.scroller)

        # 测试按钮1
        self.Button1 = wx.Button(self.RightPanel, -1, "TestButton", size=(50, 25), pos=(10, 10))
        self.Button1.Bind(wx.EVT_BUTTON, self.main_function)

        # 测试按钮2
        self.Button2 = wx.Button(self.RightPanel, -1, "AboutButton", size=(50, 25), pos=(10, 10))
        self.Button2.Bind(wx.EVT_BUTTON, self.readtable)

        # 测试按钮3
        self.Button3 = wx.Button(self.RightPanel, -1, "pause", size=(50, 25), pos=(10, 10))
        self.Button3.Bind(wx.EVT_BUTTON, self.onClick)

        # 测试按钮4
        self.Button4 = wx.Button(self.RightPanel, -1, "settable", size=(50, 25), pos=(10, 10))
        self.Button4.Bind(wx.EVT_BUTTON, self.settable)

        # 加入Sizer中
        self.FlexGridSizer.Add(self.Button1, proportion=0, border=5, flag=wx.ALL | wx.EXPAND)
        self.FlexGridSizer.Add(self.Button2, proportion=0, border=5, flag=wx.ALL | wx.EXPAND)
        self.FlexGridSizer.Add(self.Button3, proportion=0, border=5, flag=wx.ALL | wx.EXPAND)
        self.FlexGridSizer.Add(self.Button4, proportion=0, border=5, flag=wx.ALL | wx.EXPAND)

        self.FlexGridSizer.Add(ship_grid, proportion=0, border=0, flag=wx.ALL | wx.EXPAND)
        self.FlexGridSizer.Add(plane_grid, proportion=0, border=0, flag=wx.ALL | wx.BOTTOM)
        self.FlexGridSizer.Add(self.grid, proportion=0, border=0, flag=wx.ALL | wx.EXPAND)
        self.RightPanel.SetSizer(self.FlexGridSizer)

        self.BoxSizer = wx.BoxSizer(wx.HORIZONTAL)
        # self.BoxSizer.Add(self.MPL, proportion=0, border=2, flag=wx.ALL | wx.EXPAND)
        self.BoxSizer.Add(self.RightPanel, proportion=0, border=0, flag=wx.ALL | wx.EXPAND)
        self.scroller.SetSizerAndFit(self.BoxSizer)

        self.SetSizer(self.BoxSizer)

        # 状态栏
        # self.StatusBar()

        # MPL_Frame界面居中显示
        self.Centre(wx.BOTH)

There is no error in running the program. I suspect that the relationship between the scroller and the BoxSizer is not set.

来源:https://stackoverflow.com/questions/51169306/add-scrollbars-in-wxpython-but-it-doesnt-appear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!