我在网络上看到了很多滚动条,但情况却有所不同,有更多的wx.FlexGridSizer对象。
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)
运行程序没有错误。我怀疑没有设置滚动条和BoxSizer之间的关系。