本文實例為大家分享了python制作縮略圖的具體代碼,供大家參考,具體內(nèi)容如下

import cv2 #導(dǎo)入opencv模塊
from tkinter import * #導(dǎo)入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()
網(wǎng)頁題目:python如何制作縮略圖-創(chuàng)新互聯(lián)
本文來源:http://chinadenli.net/article8/cepsip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、移動網(wǎng)站建設(shè)、營銷型網(wǎng)站建設(shè)、網(wǎng)站排名、網(wǎng)站制作、網(wǎng)站維護
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)