Python Forum
[Tkinter] Image editor using Tkinter and PIL - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Image editor using Tkinter and PIL (/thread-22924.html)



Image editor using Tkinter and PIL - Raulica - Dec-03-2019

Hello! I have to make a project , more exactly an Image Editor using python and I have very very basics information about libraries in python and python and I understood than I can make it using tkinter and PIL. Now my problem is with the PIL and tkinter putting together. I have a simple interface made with some buttons and I need to add some PIL filters or whatever "rotate" , "flip" , "crop" functions from PIL . I don't know how to put the command for the buttons from the filters that PIL library gives you , I tried to put like
 button1 = Button(root , text="Filter" , command=#[there the function def] 
but it won't let me make this and if you can suggest me some filters I will be thankful!
There is what I tried to make:
from tkinter import *
from PIL import Image , ImageTk


root = Tk()
root.title('Program editare foto')
image = ImageTk.PhotoImage(Image.open("imagini/imag1.jpg"))


my_label = Label(image=image)
my_label.grid(row=1 , column=1 , columnspan=2)
my_label1 = Label(text=" ")
my_label2 = Label(text=" ")

my_label1.grid(row=0 ,column=0)
my_label2.grid(row=1 ,column=0)





button1 = Button(root , text="Filter1")
button2 = Button(root , text="Filter2")
button3 = Button(root , text="Filter3")
button4 = Button(root , text="Filter4")
button5 = Button(root , text="Filter5")
button6 = Button(root, text="Filter6")

button1.grid(row=3,column=0)
button2.grid(row=4,column=0)
button3.grid(row=5,column=0)
button4.grid(row=6,column=0)
button5.grid(row=7,column=0)
button6.grid(row=8,column=0)


root.mainloop() 
I appreciat if you help me and thank you for wasting your time seeing this! :)


RE: Image editor using Tkinter and PIL - Larz60+ - Dec-03-2019

Quote:I have very very basics information about libraries in python
see: https://pypi.org/ and python docs


RE: Image editor using Tkinter and PIL - joe_momma - Dec-03-2019

you need a function check out :
tkinter button
it's also referred as a callback, if you add a command you need a function for it.
and it must be declared before you create your button.
def my_callback():
    print('filter button pushed')
button1 = Button(root , text="Filter" , command=my_callback)
button1.pack()
I suggest using guizero to start with lawsie has recipes and documentation here:
guizero documentation