Lompat ke konten Lompat ke sidebar Lompat ke footer

Python Tkinter - How To Resize An Image In Python

How To Change Image Size And Display It In a Label Using Python Tkinter

How To Change Image Size And Display It In a Label Using Python Tkinter Python Tkinter - How To Resize An Image In Python

In This Python Tkinter Tutorial we will See How To Resize An Image And Display It On a Label .


Source Code:


import tkinter as tk
from tkinter import *
from PIL import ImageTk, Image


root = Tk()

root.title('RESIZE IMAGE')

frame = tk.Frame(root, bg='#45aaf2')

pic = "C:/Users/1BestCsharp/Desktop/book covers using canva.com/Buy My Book please.png"

# create a function to display image
def displayImages(w,h):
global img
img = Image.open(pic)
img = img.resize((w,h), Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)
lbl = tk.Label(frame)
lbl.image = img
return img

lbl_pic_path = tk.Label(frame, text='Image Path:', padx=25, pady=25,
font=('verdana',16), bg='#45aaf2')
lbl_show_pic_200 = tk.Label(frame, bg='#45aaf2', image = displayImages(200,200))
lbl_show_pic_100 = tk.Label(frame, bg='#45aaf2', image = displayImages(100,100))
lbl_show_pic_50 = tk.Label(frame, bg='#45aaf2', image = displayImages(50,50))
lbl_show_pic_25 = tk.Label(frame, bg='#45aaf2', image = displayImages(25,25))
entry_pic_path = tk.Entry(frame, font=('verdana',16))
btn_browse = tk.Button(frame, text='Select Image',bg='grey', fg='#ffffff',
font=('verdana',16))


frame.pack()

lbl_show_pic_200.grid(row=0, column=0, columnspan="2", padx=20, pady=20)
lbl_show_pic_100.grid(row=1, column=0, columnspan="2", padx=20, pady=20)
lbl_show_pic_50.grid(row=2, column=0, columnspan="2", padx=20, pady=20)
lbl_show_pic_25.grid(row=3, column=0, columnspan="2", padx=20, pady=20)

root.mainloop()


OUTPUT:

How To Change Image Size And Display It In a Label Using Python Tkinter Python Tkinter - How To Resize An Image In Python






▶ Download Python Projects Source Code

Posting Komentar untuk "Python Tkinter - How To Resize An Image In Python"