我在 tkinter 中运行了这个 matplotlib 动画,它工作正常,但它永远不会停止循环,当我按“X”时,窗口关闭,但我必须使用任务管理器强制关闭它。
这是我尝试设置它的示例代码:
from matplotlib import pyplot as plt
from matplotlib import animation
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import tkinter as tk
from tkinter import *
class Grapher(tk.Tk): # inherit Tk()
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, "Quarantined-Grapher")
self.fig = plt.figure()
ax = plt.axes(xlim=(0,2), ylim=(0, 100))
N = 4 # amount of lines
self.lines = [plt.plot([], [])[0] for _ in range(N)]
# give the figure and the root(which is self) to the "canvas"
self.canvas = FigureCanvasTkAgg(self.fig, …Run Code Online (Sandbox Code Playgroud)