import cv2 #导入opencv模块 from tkinter import * #导入tkinter模块 from tkinter import ttk #tkinter最新的主题部件 from PIL import Image #初始化模块 root = Tk() root.title('Pt') root.geometry('600x300') #查找图片路径,成功则显示图片 def searchPicture(): location = locOfPicture.get() img = cv2.imread(location) cv2.imshow("Image",img) #生成缩略图 def setPicture(): # 获取图片路径 location = locOfPicture.get() # 对图片进行操作 im = Image.open(location) im.thumbnail((int(heightOfPicture.get()),int(widthOfPicture.get()))) im.save(nameOfImg.get(),'JPEG') label1 = ttk.Label(root,text='选择图片') label2 = ttk.Label(root,text='长:') label3 = ttk.Label(root,text='宽:') label4 = ttk.Label(root,text='文件名') #存储输入框中输入的变量 locOfPicture = StringVar() heightOfPicture= StringVar() widthOfPicture = StringVar() nameOfImg = StringVar() entry1 = ttk.Entry(root,textvariable = locOfPicture,width=50) entry2 = ttk.Entry(root,textvariable=heightOfPicture,width=10) entry3 = ttk.Entry(root,textvariable=widthOfPicture,width=10) entry4 = ttk.Entry(root,textvariable=nameOfImg,width=25) button1 = ttk.Button(root,text='确定',command=searchPicture) button2 = ttk.Button(root,text='确定生成',command=setPicture) #进行界面布局 label1.grid(column=0,row=0) entry1.grid(column=1,row=0,columnspan=3) button1.grid(column=4,row=0) label2.grid(column=0,row=1) entry2.grid(column=1,row=1) label3.grid(column=2,row=1) entry3.grid(column=3,row=1) entry4.grid(column=1,row=2,columnspan=2) button2.grid(column=3,row=2) root.mainloop()