在plotcanvas

时间:2015-05-03 16:34:23

标签: python canvas wxpython

我正在尝试在Plotcanvas上绘制文本,这是代码

import wx
from wx.lib.plot import PolyLine, PlotCanvas, PlotGraphics


def drawBarGraph():
    points1=[(1,0), (1,10)]
    line1 = PolyLine(points1, colour='green', legend='Feb.', width=10)
    points1g=[(2,0), (2,4)]
    line1g = PolyLine(points1g, colour='red', legend='Mar.', width=10)
    points1b=[(3,0), (3,6)]
    line1b = PolyLine(points1b, colour='blue', legend='Apr.', width=10)

    points2=[(4,0), (4,12)]
    line2 = PolyLine(points2, colour='Yellow', legend='May', width=10)
    points2g=[(5,0), (5,8)]
    line2g = PolyLine(points2g, colour='orange', legend='June', width=10)
    points2b=[(6,0), (6,4)]
    line2b = PolyLine(points2b, colour='brown', legend='July', width=10)

    return PlotGraphics([line1, line1g, line1b, line2, line2g, line2b],
                    "Bar Graph - (Turn on Grid, Legend)", "Months", 
                    "Number of Students")


class MyGraph(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, 
                          'My First Plot (to take over the world!)')

        panel = wx.Panel(self, wx.ID_ANY)

        mainSizer = wx.BoxSizer(wx.VERTICAL)

        self.canvas = PlotCanvas(panel)
        self.canvas.Draw(drawBarGraph())

        #try to draw text on canvas
        self.canvas.Bind(wx.EVT_PAINT, self.OnPaint)

        mainSizer.Add(self.canvas, 1, wx.EXPAND)
        panel.SetSizer(mainSizer)

    def OnPaint(self, event):
        dc = wx.PaintDC(self.canvas)
        dc.DrawText("Hello World", 10, 10)

if __name__ == '__main__':
    app = wx.App(False)
    frame = MyGraph()
    frame.Show()
    app.MainLoop()

但是错误表明了这一点 self.canvas.Bind(wx.Evt_PAINT,self.OnPaint) AttributeError:'模块'对象没有属性' Evt_PAINT'。所以我想知道画布上是否有彩色和坐标的绘制文字。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

区分大小写,应写为wx.EVT_PAINT