from tkinter import *
from PIL import ImageTk,Image
import os

###USER CONFIG
#path to bliss png files (without them this will not work):
path="./blisspng/"
#image zoom divider (1 for normal size):
zoom=2
###

def Convert(string):
    li = list(string.split(" "))
    return li

root = Tk()
t = Listbox(root, background="#dddddd")
t.pack(fill=X, padx=10, expand=YES)

lab = Label()
lab.pack()
###
def callback(sv):
    sd=Convert(sv.get())
    t.delete(0,END)
    almud=[]
    for file in os.listdir("./src/"):
        if all(x in file for x in sd):
#            print('\n'.join(file.splitlines()[-10:]))
            almud.append(file)
   
    try:
        img=Image.open('./src/'+min(almud, key=len))
        imga = img.convert("RGBA")
        symb = ImageTk.PhotoImage(imga)
        symb = symb._PhotoImage__photo.subsample(zoom,zoom)
        lab.configure(image=symb)
        lab.image = symb
        label1.configure(text=min(almud, key=len))
        for i in almud[:10]:
            t.insert(END, i + '\n')
    except:
        t.insert(END, "!NOTHING FOUND!")
        nic=""
        lab.configure(image=nic)
        lab.image = nic
        label1.configure(text=nic)
    #centrum()

sv = StringVar()
sv.trace("w", lambda name, index, mode, sv=sv: callback(sv))
###

def centrum():
    w = root.winfo_reqwidth()
    h = root.winfo_reqheight()
    ws = root.winfo_screenwidth()
    hs = root.winfo_screenheight()
    x = (ws/2) - (w/2)
    y = (hs/2) - (h/2)
    root.geometry('+%d+%d' % (x, y))
###

label1 = Label(root)
label1.pack()
entry1 = Entry(root, textvariable=sv) 
entry1.pack()
entry1.focus()

#root.geometry("600x250")
root.minsize(300, 400)
centrum()
root.mainloop()
