from tkinter import *
from PIL import ImageTk, ImageFilter, Image
win = Tk()
win.title("Blur Image")
win.geometry("600x600")
D = IntVar()
def Blur(type):
d = D.get() # Convert Tkinter variable to object
oriImage = Image.open('..\\Images\\Boy.png')
if type == "Simple":
blurImage = oriImage.filter(ImageFilter.BLUR)
elif type == "Box":
blurImage = oriImage.filter(ImageFilter.BoxBlur(d))
elif type == "Gaussian":
blurImage = oriImage.filter(ImageFilter.GaussianBlur(d))
blurImage.save('..\\Images\\BoyBlur.png')
pic1 = PhotoImage(file="..\\Images\\BoyBlur.png")
lbl.config(image=pic1)
lbl.image = pic1
scl1 = Scale(win, variable=D, from_=0, to=20, orient=HORIZONTAL)
scl1.place(x=30, y=10)
btnSimpleBlur = Button(win, text="Simple Blur", command=lambda:Blur("Simple"))
btnSimpleBlur.place(x=50, y=500)
btnBoxBlur = Button(win, text="Box Blur", command=lambda:Blur("Box"))
btnBoxBlur.place(x=150, y=500)
btnGaussianBlur = Button(win, text="Gaussian Blur", command=lambda:Blur("Gaussian"))
btnGaussianBlur.place(x=250, y=500)
openImage = Image.open("..\\Images\\Boy.png")
img = ImageTk.PhotoImage(openImage)
lbl = Label(win, image=img)
lbl.place(x=30, y=60)
win.mainloop()
No comments:
Post a Comment