回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我试着把一个面板分成两个面板。
所以按钮1应该在一个面板上,按钮2,3,4应该在另一个面板上。你知道吗</p>
<p>这是我的可运行代码,它不能正确显示面板。你知道吗</p>
<pre><code>import wx
from numpy import arange, sin, pi
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
class Frame1(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, None,
pos=wx.Point(0, 0),size=wx.Size(800, 200),
style=wx.DEFAULT_FRAME_STYLE | wx.MAXIMIZE )
self.panel1 = wx.Panel(self)
self.panel2 = wx.Panel(self)
#self.panel1.SetBackgroundColour('blue')
self.panel3 = wx.Panel(self)
self.panel4 = wx.Panel(self)
self.panel3.SetBackgroundColour('red')
sizer1 = wx.BoxSizer(wx.VERTICAL)
sizer1.Add(self.panel4, 1, wx.EXPAND)
sizer1.Add(self.panel1, 1, wx.EXPAND)
self.SetSizer(sizer1)
sizer1.Fit(self)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(sizer1, 1, wx.EXPAND)
sizer.Add(self.panel2, 1, wx.EXPAND)
sizer.Add(self.panel3, 1, wx.EXPAND)
self.SetSizer(sizer)
#sizer.Fit(self)
self.log = wx.TextCtrl(self.panel3, style=wx.TE_RICH|wx.TE_MULTILINE)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.log, 1, wx.EXPAND|wx.ALL, 15)
self.panel3.SetSizer(sizer)
emptycell = (0,0)
self.button1 = wx.Button(self.panel4, -1, "Button1", size=wx.Size(150, 70))
self.button2 = wx.Button(self.panel1, -1, "Button2")
self.button3 = wx.Button(self.panel1, -1, "Button3")
self.button4 = wx.Button(self.panel1, -1, "Button4")
sizer = wx.GridSizer(8,3,0,0)
sizer.Add(emptycell, 0, wx.EXPAND)
sizer.Add(self.button1, 0, wx.ALIGN_CENTER|wx.LEFT, 10)
sizer.Add(emptycell, 0, wx.EXPAND)
sizer.Add(self.button2, 0, wx.ALIGN_CENTER)
sizer.Add(self.button3, 0, wx.ALIGN_CENTER)
sizer.Add(self.button4, 0, wx.ALIGN_CENTER)
self.panel1.SetSizer(sizer)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self.panel2, -1, self.figure)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.canvas, 0, wx.EXPAND)
self.panel2.SetSizer(sizer)
#self.panel2.Fit()
t = arange(0.0, 3.0, 0.01)
s = sin(2 * pi * t)
self.axes.plot(t, s)
#self.Center()
#Every wxWidgets application must have a class derived from wxApp
class MyApp(wx.App):
# wxWidgets calls this method to initialize the application
def OnInit(self):
# Create an instance of our customized Frame class
self.frame = Frame1(None)
self.SetTopWindow(self.frame)
self.frame.Show()
return True
if __name__ == '__main__':
application = MyApp(0)
application.MainLoop()
</code></pre>
<p>期望结果</p>
<p><a href="https://i.stack.imgur.com/kVyiV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kVyiV.png" alt="enter image description here"/></a></p>
<p>实际结果</p>
<p><a href="https://i.stack.imgur.com/HPrYg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HPrYg.png" alt="enter image description here"/></a></p>