import tkinter
from tkinter import *
from PIL import Image,ImageTk
from tkinter.filedialog import askopenfilename
root = Tk()
root.geometry('800x500')
root.title('图片处理')
def resize(w, h, pil_image):
f1 = 1.0 * 800 / w # 1.0 forces float division in Python2
f2 = 1.0 * 500 / h
factor = min([f1, f2])
width = int(w * factor)
height = int(h * factor)
return pil_image.resize((width, height), Image.ANTIALIAS)
def choosepic():
path_ = askopenfilename()
path.set(path_)
img_open = Image.open(file_entry.get())
reimg=resize(img_open.width, img_open.height, img_open)
img = ImageTk.PhotoImage(reimg)
image_label.config(image=img)
image_label.image = img # keep a reference
# result.config(text='dffffff')
path = StringVar()
Button(root, text='选择图片', command=choosepic).pack()
# result=tkinter.Label(text='识别结果显示区域',font=('Arial',12))
# result.pack(side=tkinter.BOTTOM)
file_entry = Entry(root, state='readonly', text=path)
image_label = Label(root)
image_label.pack(padx=60, pady=60)
root.mainloop()
python读取并显示照片
猜你喜欢
转载自blog.csdn.net/weixin_41967600/article/details/100767747
今日推荐
周排行