- import tkinter as tk
- from PIL import ImageTk, Image
- win=tk.Tk()
- win.title("調整圖片大小")
- win.resizable(0,0)
- img=Image.open("pic/01.jpg")
- w=img.width
- h=img.height
- print(w, h)
- img2=img.resize((int(w*0.7),int(h*0.7)))
- pi=ImageTk.PhotoImage(img2)
- # img3=Image.open("pic/01.jpg").resize((200,150))
- # img3=Image.open("pic/01.jpg").resize((int(img.width*0.5),int(img.height*0.5)))
- # pi=ImageTk.PhotoImage(img3)
- lb=tk.Label(win,image=pi).pack()
- win.mainloop()
複製代碼 |