sélectionner un dossier !! et un peu de gc

yipee
This commit is contained in:
dovbaeb committed 2026-11-04 15:13:59 +01:00
1 parent 09e7d9410a
commit 95f0f20a0e
1 file changed
+25 -47
+25 -47
View File
@@ -5,65 +5,43 @@ from tkinter import ttk
from PIL import Image, ImageTk from PIL import Image, ImageTk
import os import os
from os import listdir from os import listdir
from tkinter import filedialog
parent = tk.Tk() parent = tk.Tk()
parent.title("Perlinator") parent.title("Perlinator")
parent.minsize(320, 240) parent.minsize(320, 240)
def button_clicked(): def upload_folder():
global isittrue folder_path = filedialog.askdirectory()
if isittrue == 0: if folder_path:
image2 = Image.open("test/tux.jpg") image_files = [
image2 = ImageTk.PhotoImage(image2) f
image_label.configure(image=image2) for f in listdir(folder_path)
image_label.image = image2 if f.lower().endswith((".png", ".jpg", ".jpeg", ".gif"))
isittrue = 1 ]
print(f"Found {len(image_files)} images in {folder_path}:")
for image_file in image_files:
print(image_file)
open_button.pack(pady=10)
else: else:
image_label.configure(image=img) popup = tk.Toplevel(parent)
image_label.image = img popup.title("No Folder Selected")
isittrue = 0 popup.geometry("300x100")
label = tk.Label(popup, text="No folder selected.")
label.pack(pady=20)
popup.after(2000, popup.destroy)
isittrue = 0 open_button = tk.Button(
button = tk.Button(
parent, parent,
text="Click Me",
command=button_clicked,
activebackground="blue",
activeforeground="white",
anchor="center", anchor="center",
bd=3,
bg="lightgray",
cursor="hand2", cursor="hand2",
disabledforeground="gray", text="Selectionner le dossier d'images",
fg="black", command=upload_folder,
font=("Arial", 12),
height=2,
highlightbackground="black",
highlightcolor="green",
highlightthickness=2,
justify="center",
overrelief="raised",
padx=10,
pady=5,
width=15,
wraplength=100,
) )
open_button.pack(pady=10)
button.pack(padx=20, pady=20)
folder_dir = "./test/"
for images in os.listdir(folder_dir):
if images.endswith(".png") or images.endswith(".jpg") or images.endswith(".jpeg"):
print(images)
img = Image.open("test/logo.png")
img = ImageTk.PhotoImage(img)
image_label = tk.Label(parent, image=img)
image_label.pack()
parent.mainloop() parent.mainloop()