Мне нужно просмотреть мою галерею, используя python.
Это мой код:
import sys
import matplotlib as plt
from tkinter import *
from tkinter import ttk
import tkinter.filedialog
from tkinter.filedialog import askopenfilename # Open dialog box
from PIL import Image
import cv2, time
def open_File():
filename = askopenfilename(filetypes=[("images","*.png")])
img = filename.read()
#cv2.imshow("Shapes", filename) # I used cv2 to show image
#cv2.waitKey(0)
filename.close()
rw = Tk() # Create window
rw.title("Browse image") #
l1=Label(rw, text="Select image")
l1.grid(row=0,column=0)
btn1=Button(rw,text="Browse image", width =14)
btn1.grid(row=0, column=3)
btn1.config(command=open_File)
rw.mainloop()
но я получаю эту ошибку:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Akhou\Anaconda3\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:/Users/Akhou/Desktop/PFE altran/shape detection/ShapesDetection/PythonApplication2/browse.py", line 31, in open_File
img = filename.read()
AttributeError: 'str' object has no attribute 'read'
Можете ли вы помочь мне, пожалуйста