# -*- coding: utf-8 -*-
import cv2
import numpy as np
from tkinter import filedialog
import tkinter as tk
from PIL import ImageTk, Image
root = tk.Tk()
videoFrame = tk.Frame(root).pack()
video = tk.Label(videoFrame)
video.pack()
def cv_imread(filePath):
cv_img=cv2.imdecode(np.fromfile(filePath,dtype=np.uint8),-1)
return cv_img
def oas():
sfname = filedialog.askopenfilename(title='選擇',
filetypes=[
('All Files','*'),
("jpeg files","*.jpg"),
("png files","*.png"),
("gif files","*.gif")])
im = cv_imread(sfname)
cv2image = cv2.cvtColor(im, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img)
video.imgtk = imgtk
video.configure(image=imgtk)
B1 = tk.Button(root, text="打開",command = oas).pack()
root.mainloop()