python中使用import matplotlib.pyplot as plt的plt保存图片的时候,前三次总是没问题,第四次总是报错。

报错如下:

Exception ignored in: <bound method Image.__del__ of <tkinter.PhotoImage object at 0x000001B31B4E6470>>
Traceback (most recent call last):
File "C:\Python\Python36\lib\tkinter\__init__.py", line 3507, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Exception ignored in: <bound method Image.__del__ of <tkinter.PhotoImage object at 0x000001B31B4D5EB8>>
Traceback (most recent call last):
File "C:\Python\Python36\lib\tkinter\__init__.py", line 3507, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Exception ignored in: <bound method Image.__del__ of <tkinter.PhotoImage object at 0x000001B31B52F128>>
Traceback (most recent call last):
File "C:\Python\Python36\lib\tkinter\__init__.py", line 3507, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread

解决办法:

# import matplotlib.pyplot as plt

import matplotlib

matplotlib.use('Agg')

from matplotlib import pyplot as plt

用下面的三行替换掉引用的一行即可

import sympy as sp # 导入sympy包 x = sp.Symbol('x') # 定义符号变量 f = x**3 - 3*x**2 + 3*x - 9/16 # 定义要求解的一元 三次 方程 x = sp.solve(f) # 调用solve函数求解方程 x # solve函数的返回结果是一个列表 # x的值为[0.240852757031084,1.37957362148446-0.657440797623999*I,1.379573621484 Python Matplotlib: 解决 Tcl_AsyncDelete: async handler deleted by the wrong thread 在同时使用PyQt5中的QThread和matplotlib.pyplot时,虽然一开始所有的图形都能顺利生成,但是在关闭窗口的时候,就会生成以下的错误: Error in atexit._run_exitfuncs: Trace... 一开始我以为是多线程的问题,后来才发现是matplotlib.pyplot造成的问题。matplotlib.pyplot在运行的时候,是需要在主线程(Main Thread)上运行的,然而,我在使 matplotlib画图出错RuntimeError: main thread is not in main loop 使用pytorch跑网络 报错 self.tk.call('image', 'delete', self.name) RuntimeError: main thread is not in main loop Tcl_AsyncDelete: async handler deleted by the wrong thread matplotlib的默认backend是TkAgg,而 Exception ignored in: &lt;bound method PhotoImage.__del__ of &lt;tkinter.PhotoImage object at 0x0000000014FCFB70&gt;&gt;Traceback (most recent call last):  File "C:\ Python 34\lib\tkinter\__init__.py", ... 开始工作了。这是密码class Mainframe(tk.Frame):def __init__(self,master,*args,**kwargs):super(Mainframe,self).__init__(master,*args,**kwargs)self.meter = Meter(self,height = 400,width = 400)self.meter.setrange(2... python 报错 :Traceback (most recent call last): … python 报错 : Traceback (most recent call last): File "C:/Users/86177/PycharmProjects/untitled/csdn浏览量.py", line 1, in <module> import requests File "G:\PyCharm 2019.3\1\lib\site-packages\requests\__i I have a python program which is scraping web data for a client. tkinter is used for the interface. Outline is:Window 1 lets the user select what information to scrape.Window 1 closesSeparate thread i... import cv2 import numpy as np srcImage = cv2.imread(&amp;quot;E:/Study/ python /OpenCV_study/img/dota.jpg&amp;quot;) value = 500 ROI = srcIma...