【发布时间】:2022-07-05 23:58:15
【问题描述】:
我正在尝试运行以下代码,它运行成功...但是当我尝试导入 matplotlib 时它给出错误----> _tkinter.TclError: image "pyimage1" doesn't exist while using PyCharm, 但是使用 python IDLE 它可以正常工作。
import cv2
from tkinter import *
from PIL import Image, ImageTk
import datetime
import openpyxl
#from matplotlib import pyplot as plt
def show_frames():
im = cap.read()[1]
Image1= cv2.cvtColor(im,cv2.COLOR_BGR2RGB)
img = Image.fromarray(Image1)
imgtk = ImageTk.PhotoImage(image = img)
label.imgtk = imgtk
label.configure(image=imgtk)
label.after(20, show_frames)
def capture():
I = cap.read()[1]
save_name = str(datetime.datetime.now().today()).replace(":", " ") + ".jpg"
cv2.imwrite(save_name, I)
#here creating window and GUI
win = Tk()
win.geometry("1200x650")
win.title('Portable Optical Spectrometer')
L2 = Label(win,text = " Camera ",font=("times new roman",20,"bold"),bg="white",fg="red").grid(row=0, column=0)
L2 = Label(win,text = " Spectrum Graph ",font=("times new roman",20,"bold"),bg="white",fg="red").grid(row=0, column=2)
label =Label(win)
label.grid(row=1, column=0)
cap = cv2.VideoCapture(0)
show_frames()
B1 = Button(win,text="Capture",font=("Times new roman",20,"bold"),bg="white",fg="red",command=capture()).grid(row=3, column=0, )
B1 = Button(win,text="Analysis",font=("Times new roman",20,"bold"),bg="white",fg="red",).grid(row=4, column=0)
L1 = Label(win,text = "Detected Material is: ",font=("times new roman",20,"bold"),bg="white",fg="red").grid(row=4, column=1)
Output = Text(win, height = 3,width = 25,bg = "light cyan").grid(row=4, column=2)
win.mainloop()
cap.release()
有人可以建议如何解决这个错误
【问题讨论】:
标签: python matplotlib tkinter