我想在嵌套boxsizer(在vbox中为hbox)内绘制图,所以我可以在面板内部使用图(不像matplotlib,它似乎使用它自己的面板)。如果我尝试运行我的代码,它根本不会显示/绘制画布。
我试图将图放到vboxMain中,并且一旦我将画布放到hbox中就无法使用了。
import wx
from wx.lib.plot import PolyLine, PlotCanvas, PlotGraphics
def drawBarGraph():
points=[(1,0), (3,10)]
line = PolyLine(points)
return PlotGraphics([line])
class MyFrame(wx.Frame):
def __init__(self,parent,title):
wx.Frame.__init__(self, parent, title = title, size = (400,400))
self.panel = wx.Panel(self)
#building layout
self.vboxMain = wx.BoxSizer(wx.VERTICAL)
hboxContent = wx.BoxSizer(wx.HORIZONTAL)
#canvas
canvas = PlotCanvas(self.panel)
canvas.Draw(drawBarGraph())
#add everything together
hboxContent.Add(canvas,1, wx.EXPAND)
self.vboxMain.Add(hboxContent)
self.panel.SetSizer(self.vboxMain)
self.panel.Layout()
self.Show(True)
app = wx.App(False)
frame = MyFrame(None, 'TestApp')
app.MainLoop()
我想在hbox中显示画布