Image search browser with Tkinter

Viewed 185

I'm trying to do an image search engine with Tkinter. Basically a "Pokedex" that searches for images inside a specific folder on my computer associated with a specific name.Example of the image output

import tkinter as tk
from io import BytesIO
import matplotlib.pyplot as plt
import os
import glob
import natsort
from PIL import Image
from PIL import ImageTk

window = tk.Tk()
window.geometry("600x500")
window.title("CoreaninhaDex")
window.config(padx=10, pady=10)

title_label = tk.Label(window, text = 'CoreaninhaDex')
title_label.config(font=('Arial', 32))
title_label.pack(padx=10, pady=10)

target_image = tk.Label(window)
target_image.pack(padx=10, pady=10)

target_information = tk.Label(window)
target_information.config(font=("Arial", 20))
target_information.pack(padx=10, pady=10)

photos_names_list = ["target1","target2","target3","target4","target5"]
#FUNCTION
def showimage():

    dir1 = r"C:\Users\path"
    path1 = os.path.join(dir1, '*g')
    files = glob.glob(path1)
    files1 = natsort.natsorted(files, reverse=False)
    for x in files1:
        img = plt.imread(x)
        image = Image.open(img)
        imag = ImageTk.PhotoImage(image)


    target_image.config(image=imag)
    target_image.image = imag




label_id_name = tk.Label(window, text="ID or Name")
label_id_name.config(font=("Arial", 20))
label_id_name.pack(padx=10, pady=10)

text_id_name = tk.Text(window, height = 1)
text_id_name.config(font=("Arial", 20))
text_id_name.pack(padx=10, pady=10)

btn_load = tk.Button(window, text="Load target", command = showimage)
btn_load.config(font=("Arial", 20))
btn_load.pack(padx=10, pady=10)

window.mainloop()

The output generates a display. But I can't associate the image with any name or even upload the images.

I would like help to write a showimage () function that would do this.

0 Answers
Related