How to put a plot in a nested wx.boxsizer

88 Views Asked by At

I want to make a plot within a nested boxsizer (hbox in vbox), so i can use a plot inside my panel (not like the matplotlib, which seems to use it's own panel). if i try to run my code it simply doesn't show/draw the canvas.

I tried to put the plot into the vboxMain and it works, as soon as i put the canvas into the hbox it doesn't.

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()

I want to show the canvas in my hbox

0

There are 0 best solutions below