_tkinter.TclError: can't invoke “update” command: application has been destroyed error on pyplot.pause()
_tkinter.TclError: can't invoke “update” command: application has been destroyed error on pyplot.pause()
我正在处理来自 arduino 的串行数据,并使用 opencv2 和 matplotlib 库处理 python 中的数据。一切正常,但每次我关闭图形 window 我都收到错误,而我什至不使用 tkinter 库。
Traceback (most recent call last):
File "C:\Users\LENOVO\Documents\Arduino\project\coba.py", line 57, in <module>
plt.pause(0.2)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\pyplot.py", line 438, in pause
canvas.start_event_loop(interval)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\backend_bases.py", line 2407, in start_event_loop
self.flush_events()
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\backends\_backend_tk.py", line 390, in flush_events
self._master.update()
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1305, in update
self.tk.call('update')
_tkinter.TclError: can't invoke "update" command: application has been destroyed
我什至没有声明 tkinter 库,
import cv2
import serial
import numpy as np
import matplotlib.pyplot as plt
这里使用 matplotlib 是为了实时并排显示来自摄像头的视频和串行数据输出,当我按下 'q' 时应用程序应该关闭。
#create two subplots
ax1 = plt.subplot(1,2,1)
ax2 = plt.subplot(1,2,2)
#create two image plots
im1 = ax1.imshow(grab_frame(video))
im2 = plt.imshow(cap2)
while True:
#read from serial
buffer = port.readline()
temper = buffer.decode('utf-8')
temper = temper.reshape(8,8)
#update data
im1.set_data(grab_frame(video))
im2.set_data(temper)
plt.pause(0.2)
#stopper
key = cv2.waitKey(1)
if(key == ord('q')):
break
plt.show()
video.release()
cv2.destroyAllWindows()
我应该使用 tkinter 库吗?
我已经尝试了一些方法来克服它,但我仍然不知道用 tkinter 完成的地方,但 IMO 是关于我无法关闭程序时它被暂停了。所以,我没有将塞子放在底部,而是放在 plt.pause()
上方。这看起来像这样:
#update data
im1.set_data(grab_frame(video))
im2.set_data(temper)
#stopper
key = cv2.waitKey(1)
if(key == ord('q')):
break
plt.pause(0.2)
我正在处理来自 arduino 的串行数据,并使用 opencv2 和 matplotlib 库处理 python 中的数据。一切正常,但每次我关闭图形 window 我都收到错误,而我什至不使用 tkinter 库。
Traceback (most recent call last):
File "C:\Users\LENOVO\Documents\Arduino\project\coba.py", line 57, in <module>
plt.pause(0.2)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\pyplot.py", line 438, in pause
canvas.start_event_loop(interval)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\backend_bases.py", line 2407, in start_event_loop
self.flush_events()
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\backends\_backend_tk.py", line 390, in flush_events
self._master.update()
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1305, in update
self.tk.call('update')
_tkinter.TclError: can't invoke "update" command: application has been destroyed
我什至没有声明 tkinter 库,
import cv2
import serial
import numpy as np
import matplotlib.pyplot as plt
这里使用 matplotlib 是为了实时并排显示来自摄像头的视频和串行数据输出,当我按下 'q' 时应用程序应该关闭。
#create two subplots
ax1 = plt.subplot(1,2,1)
ax2 = plt.subplot(1,2,2)
#create two image plots
im1 = ax1.imshow(grab_frame(video))
im2 = plt.imshow(cap2)
while True:
#read from serial
buffer = port.readline()
temper = buffer.decode('utf-8')
temper = temper.reshape(8,8)
#update data
im1.set_data(grab_frame(video))
im2.set_data(temper)
plt.pause(0.2)
#stopper
key = cv2.waitKey(1)
if(key == ord('q')):
break
plt.show()
video.release()
cv2.destroyAllWindows()
我应该使用 tkinter 库吗?
我已经尝试了一些方法来克服它,但我仍然不知道用 tkinter 完成的地方,但 IMO 是关于我无法关闭程序时它被暂停了。所以,我没有将塞子放在底部,而是放在 plt.pause()
上方。这看起来像这样:
#update data
im1.set_data(grab_frame(video))
im2.set_data(temper)
#stopper
key = cv2.waitKey(1)
if(key == ord('q')):
break
plt.pause(0.2)