我的函数不知道是否需要第二个参数(python、matplotlib)

我的函数不知道是否需要第二个参数(python、matplotlib),python,matplotlib,tkinter,Python,Matplotlib,Tkinter,我正在用Python编写一个(应该是)简单的程序,使用Tkinter和Matplotlib来控制机器。这是我的第一个Python程序,因此对于任何异常的非约定表示歉意,我欢迎所有反馈。另外,很抱歉代码块太大 我试图为控件创建一个主页面,并在计算机运行时创建一个显示图形的辅助页面。我已经设法让第二页正确地显示和消失,并显示图表。然而,每次它在图表中添加一个点时,它都会对我大喊大叫 > Exception in Tkinter callback Traceback (most recent

我正在用Python编写一个(应该是)简单的程序,使用Tkinter和Matplotlib来控制机器。这是我的第一个Python程序,因此对于任何异常的非约定表示歉意,我欢迎所有反馈。另外,很抱歉代码块太大

我试图为控件创建一个主页面,并在计算机运行时创建一个显示图形的辅助页面。我已经设法让第二页正确地显示和消失,并显示图表。然而,每次它在图表中添加一个点时,它都会对我大喊大叫

> 
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.4/tkinter/__init__.py", line 1536, in __call__
    return self.func(*args)
  File "/usr/lib/python3.4/tkinter/__init__.py", line 585, in callit
    func(*args)
TypeError: graph_animate() missing 1 required positional argument: 'i'
因此,我从我的图形函数中删除了“I”参数,因此它只需要(self),然后它以不同的方式对我大喊大叫:

> 
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/matplotlib/figure.py", line 381, in show
    manager = getattr(self.canvas, 'manager')
AttributeError: 'FigureCanvasTkAgg' object has no attribute 'manager
然后是文件和模块中的一系列位置,最后是:

> 
....File "/usr/local/lib/python3.4/dist-packages/matplotlib/animation.py", line 1212, in _draw_frame
    self._drawn_artists = self._func(framedata, *self._args)
TypeError: graph_animate() takes 1 positional argument but 2 were given
我对Python中的疑难解答不是很熟悉,但它似乎是一个catch-22类型的协议,我指定了另一个参数,它说我没有,所以我取出它,它说它太多了。我花了相当多的时间试图弄清楚发生了什么,以及tkinter中如何指定构造函数,但我仍然无法修复错误

import matplotlib
matplotlib.use("TkAgg")
import matplotlib.animation as animation
from matplotlib import style
import datetime
import time
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import tkinter as tk
from tkinter import ttk, StringVar
import urllib
import json
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt

f = Figure()
a = f.add_subplot(111)
gsFurnaceTemp = 0
plottime = []
plottemp = []

class BrokeApp:
    global gsFurnaceTemp
    def __init__(self, parent):

        self.myParent=parent
        self.root=parent

        self.myContainer1=tk.Frame(parent)
        self.myContainer1.pack()

        label = tk.Label(self.myContainer1, text = "My Broken App")
        label.grid(columnspan=4)
        buttonStart=tk.Button(self.myContainer1, text="Start Run",
                              bg='green', height=3, width=20,
                              command = self.btnStartClick)
        buttonStart.grid(row=7, column=1)

        self.ChillerLabelText = StringVar()
        self.ChillerLabelText.set(gsFurnaceTemp)
        lblChillerTemp = tk.Label(self.myContainer1, textvariable=self.ChillerLabelText)
        lblChillerTemp.grid(row=100, column=100)

        self.getDataTimer()

    def btnStartClick(self):
        self.newWindow=tk.Toplevel(self.myParent)
        self.app=GraphPage(self.newWindow)

    def getDataTimer(self):
        gsFurnaceTemp=open("TempTxt.txt", "r").read()
        self.ChillerLabelText.set(str(gsFurnaceTemp))
        self.root.after(1000, self.getDataTimer)


class GraphPage:
    global gsFurnaceTemp
    def __init__(self, parent):
        self.myParent=parent
        self.root=parent
        self.master=parent

        self.plottempz = []
        self.plottimez = []
        self.fz = Figure()
        self.az = self.fz.add_subplot(111)

        self.myContainer1=tk.Frame(parent)
        self.myContainer1.pack()

        label = tk.Label(self.myContainer1, text = "Temp Graph")
        label.pack(pady=10, padx=10)

        btnStartPage = ttk.Button(self.myContainer1, text="Back to Main Page",
                           command = self.close_Window)
        btnStartPage.pack(padx = 10, pady = 10)

        canvas = FigureCanvasTkAgg(self.fz, self.myContainer1)
        canvas.show()
        canvas.get_tk_widget().pack() 

        plottemp= []
        plottime= []

        ani = animation.FuncAnimation(self.fz, self.graph_animate, interval=1000)
        self.fz.show()


    def graph_animate(self, i):  #THIS IS THE LOCATION WHERE I REMOVE AND
                                 #INSERT THE ", i" WHICH HAS BEEN GIVING ME TROUBLES
        gsFurnaceTemp=open("TempTxt.txt", "r").read()
        plottemp.append(gsFurnaceTemp)
        self.az.clear()
        self.az.plot(plottemp)

        self.root.after(1000, self.graph_animate)

        gsFurnaceTemp=open("TempTxt.txt", "r").read()

    def close_Window(self):
        self.master.destroy()


def main():
    root = tk.Tk()
    app = BrokeApp(root)
    root.geometry("800x600")
    root.mainloop()
if __name__ == "__main__":
    main()
另外,如果此代码中有任何代码是多余的,或者我声明的任何变量未使用,请道歉。我的大脑在想如何从更大的程序中把它压缩成一个足够短但可编译的块的时候,简直快炸了


Steeeve

我必须定义,您可以检查“帧”在动画中的工作方式。我建议您阅读有关matplotlib.animation.FuncAnimation的文档

我甚至在没有错误消息的情况下运行它也会出错,这让我非常困惑,因为我以前从未见过Python在没有错误消息的情况下崩溃。也许
attext.txt
的内容会有所帮助?该文件的内容只是:“125”,没有引号。我尝试了不同的数字,它们都起作用了,我可以绘制数字图,但不能不抛出“您需要指定I”的错误