我有多个面板(当前为6个),单击“下一步”按钮时,该面板将更改为下一个面板。效果很好,但现在我想使用splitterwindow更改布局,当前面板显示在左上方窗口中,最终(在面板6上)单击图按钮时,图将显示在右上方面板上。>
我找不到结合使用splitterwindow在面板之间进行切换的好例子。
下面是只有两个面板的最小工作示例。布局正确,当前显示打开的第二个面板。但是,没有一个按钮处于活动状态。我也不知道如何将图FigureCanvas显示在左上方的面板上。
import wx
import wx.lib.scrolledpanel as scrolled
import matplotlib as mpl
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
class MyApp(wx.App):
def __init__(self):
super().__init__(clearSigInt=True)
self.InitFrame()
def InitFrame(self):
frame = MyFrame(parent=None, title='Prototype', pos = (100,100))
frame.Show()
class RandomPanel(wx.Panel):
def __init__(self, parent, color):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.SetBackgroundColour(color)
class MyFrame(wx.Frame):
def __init__(self, parent, title, pos):
super().__init__(parent=parent, title=title, pos=pos)
self.OnInit()
def OnInit(self):
self.panel_one = First(self)
self.panel_two = Second(self, self.panel_one)
topSplitter = wx.SplitterWindow(self)
top = wx.SplitterWindow(topSplitter)
topL_one = Second(top, self.panel_one)
topR = RandomPanel(top, "red")
top.SplitVertically(topL_one, topR)
top.SetSashGravity(0.5)
bottom = RandomPanel(topSplitter, "green")
topSplitter.SplitHorizontally(top, bottom)
topSplitter.SetSashGravity(0.5)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(topSplitter, 1, wx.EXPAND)
self.SetSizer(sizer)
self.panel_one = First(self)
self.panel_two = Second(self, self.panel_one)
self.panel_one.btn_Fwd.Bind(wx.EVT_BUTTON, self.show_panel_two)
self.panel_one.btn_Fwd.Bind(wx.EVT_BUTTON, self.panel_two.onPlot)
self.panel_two.btn_Bck.Bind(wx.EVT_BUTTON, self.back_panel_one)
self.panel_two.btn_Bck.Bind(wx.EVT_BUTTON, self.panel_one.onFirst)
self.panel_two.Hide()
self.Centre()
def show_panel_two(self, event):
self.topL_one.panel_two.Show()
self.topL_one.panel_one.Hide()
self.Layout()
event.Skip()
def back_panel_one(self, event):
self.panel_one.Show()
self.panel_two.Hide()
self.Layout()
class First(wx.Panel):
def __init__(self, parent):
super().__init__(parent=parent)
self.btn_Fwd = wx.Button(self, -1, "Next", (450, 20))
self.btn_Bck = wx.Button(self, -1, "Back", (50, 20))
oneText = wx.StaticText(self, id=wx.ID_ANY, label='One', pos=(50,80))
def onFirst(self, event):
dataText = wx.StaticText(self, id=wx.ID_ANY, label='This is the first panel', pos=(50,120))
class Second(scrolled.ScrolledPanel):
def __init__(self, parent, first_panel):
super().__init__(parent=parent)
self.first_panel = first_panel
self.btn_Fwd = wx.Button(self, -1, "Next", (450, 20))
self.btn_Bck = wx.Button(self, -1, "Back", (50, 20))
twoText = wx.StaticText(self, id=wx.ID_ANY, label='Two', pos=(50,80))
plot_button = wx.Button(parent=self, label = "Plot", pos = (50,150))
plot_button.Bind(event=wx.EVT_BUTTON, handler=self.onPlot)
def onPlot(self,event):
x = np.arange(10)
y = np.arange(10)
self.figure = mpl.figure.Figure(figsize=(5, 5))
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
self.canvas.Show(True)
self.axes.plot(x, y)
if __name__ == "__main__":
app = MyApp()
app.MainLoop()
有人知道如何以这种方式组合开关面板和分离器窗口吗?