I try build mini application where I set image to application. It's works, but I have problem with one thing. I try using the function easy.fileopenbox get path to file and I need print it to entry object. Below my full code, where comment "<-----" shows discussed topic. Probably it's a easy case but I'm new in Python. Thanks!
from tkinter.ttk import Frame, Style, Label, Entry, Button, Combobox
from tkinter import BOTH, Tk, W, E, N, S, Canvas, NW
from PIL import Image, ImageTk
import easygui
max_h=500
max_w=900
class Okno(Frame):
def __init__(self, parent):
super().__init__(parent)
self.parent=parent
self.inicjalizuj()
def wczytaj_ponownie(self):
self.image=ImageTk.PhotoImage(self.im)
self.podst.create_image(0,0, image=self.image, anchor=NW)
def wczytaj_obraz(self):
sciezka=easygui.fileopenbox(msg=('Wskaż odpowiedni plik'), default="C:/Users/Darkous/Desktop/tutorial/IMAGE/*.jpg") ##self.o.get()
print(sciezka)
self.o=sciezka ## -- here i try set value from sciezka to object
self.im=Image.open(sciezka)
self.fbtn.config(state='normal')
self.zbtn.config(state='normal')
self.sbtn.config(state='normal')
self.pbtn.config(state='normal')
self.obraz_oryg=self.im
self.wczytaj_ponownie()
def zapisz(self):
sciezka=self.z.get()
if sciezka=='':
sciezka=self.o.get()
self.im.save(sciezka)
def inicjalizuj(self):
self.parent.title("Kurs Pythona")
self.styl=Style()
self.styl.theme_use("winnative")
self.pack(fill=BOTH,expand=1)
self.columnconfigure(1,weight=1)
etykieta=Label(self, text="Ścieżka do pliku:")
etykieta.grid(sticky=W, pady=4, padx=5)
self.o=Entry(self) ## I inicialize object <--------------------------------
self.o.grid(row=1, column=0, columnspan=2, rowspan=1, padx=5, pady=4, sticky=E+W+S+N)
self.z=Entry(self)
self.z.grid(row=2, column=0, columnspan=2, rowspan=1, padx=5, pady=4, sticky=E+W+S+N)
otbtn=Button(self, text="Otwórz", command=self.wczytaj_obraz)
otbtn.grid(row=1,column=3)
self.zbtn=Button(self, text="Zapisz", command=self.zapisz)
self.zbtn.grid(row=2,column=3)
self.zbtn.config(state="disabled")
self.sxbox=Combobox(self, values='0.1 0.2 0.3 0.4')
self.sxbox.grid(row=3, column=0, pady=4, padx=5, sticky=W+N)
self.fcbox=Combobox(self, values='BLUR CONTOUR EMBOSS')
self.fcbox.grid(row=4, column=0, pady=4, padx=5, sticky=W+N)
self.sbtn=Button(self, text="Skaluj")
self.sbtn.grid(row=3,column=1, pady=4, padx=5, sticky=W+N)
self.sbtn.config(state="disabled")
self.fbtn=Button(self, text="Filtruj")
self.fbtn.grid(row=4,column=1, pady=4, padx=5, sticky=W+N)
self.fbtn.config(state="disabled")
self.podst=Canvas(self, width=max_h, height=max_h)
self.podst.grid(row=5, column=0, pady=4, padx=5, sticky=E+W+S+N, columnspan=3)
self.pbtn=Button(self, text="Przywróć")
self.pbtn.grid(row=5,column=3, pady=4, padx=5, sticky=W+N)
self.pbtn.config(state="disabled")
def main():
gui=Tk()
gui.geometry("1000x700")
app=Okno(gui)
gui.mainloop()
if __name__ == '__main__':
main()