scale组件缩放图像大小_tkinter显示与pillow图形处理

scale组件缩放图像大小_tkinter显示与pillow图形处理

李兴球Pythonscale组件tkinter缩放图像pillow调整图像大小
李兴球Pythonscale组件tkinter缩放图像pillow调整图像大小

李兴球Pythonscale组件tkinter缩放图像pillow调整图像大小

from tkinter import *
from PIL import Image,ImageTk

def resize(value):
    global catimg 
    k = int(value) / 100
    w,h = cat.size
    w,h = int(w * k),int(h * k)
    cat2 = cat.resize((w,h))
    root.title(cat2.size)
    catimg = ImageTk.PhotoImage(cat2)
    cv.itemconfig(pic,image=catimg)
    #cv.update()
    
root = Tk()

b1= Scale(root,length=200,orient=HORIZONTAL,from_=50,to=200,
            activebackground='red',command=resize)
b1.pack()

cat = Image.open('cat.png')
catimg = ImageTk.PhotoImage(cat)
cv = Canvas(root,width=280,height=360,bg='white')
cv.pack()

pic = cv.create_image(140,180,image=catimg,anchor='center')
resize('50')

root.mainloop()

李兴球

李兴球的博客是Python创意编程原创博客