Plotting data in Tkinter with matplotlib - switching between lists

前端 未结 1 1575
南笙
南笙 2021-01-24 09:23

I\'m working on creating a program that utilizes Tkinter and matplotlib. I have 2 lists of lists (one for x-axis, one

相关标签:
1条回答
  • 2021-01-24 09:42

    The AttributeError: App instance has no attribute 'canvas' means that your code references the canvas attribute before it has been created/assigned.

    This line:

    self.button_left = Button(frame,text="< Previous Event",
                                        command=self.decrease(event_num))
    

    is calling the decrease method because you used parentheses and provided arguments instead of just binding the handler. Inside the decrease method, you're accessing self.canvas to call the draw method.

    That is happening before you create the canvas attribute, which happens on this line:

    self.canvas = FigureCanvasTkAgg(fig,master=master)
    

    Make event_num an attribute of the App object; then you won't have to pass arguments to the handler when you bind it. You can do this by assigning self.event_num = 1 inside __init__.

    0 讨论(0)
提交回复
热议问题