import os
import glob
from tkinter import *
from PIL import Image, ImageTk
def choose_directory():
global filepath
filepath = filedialog.askdirectory()
def read_images():
global images
images = []
for file in glob.glob(filepath + "/*.png") + glob.glob(filepath + "/*.jpg"):
image = Image.open(file)
images.append(image)
def display_images():
global current_image
current_image = 0
global image_label
image_label = Label(image_display_frame)
image_label.pack()
show_image()
root.after(2000, display_images)
def show_image():
global current_image
global images
if current_image == len(images):
current_image = 0
image = images[current_image].resize((800, 600))
photo = ImageTk.PhotoImage(image)
image_label.configure(image=photo)
image_label.image = photo
current_image += 1
def switch_view():
global current_view
if current_view == "gallery":
image_display_frame.pack_forget()
file_display_frame.pack()
current_view = "file explorer"
switch_button.configure(text="Switch to Gallery View")
else:
file_display_frame.pack_forget()
image_display_frame.pack()
current_view = "gallery"
switch_button.configure(text="Switch to File Explorer View")
root = Tk()
root.title("Image Viewer")
root.geometry("800x600")
filepath = ""
images = []
current_image = 0
current_view = "file explorer"
# File Explorer View
file_display_frame = Frame(root)
file_display_frame.pack()
choose_button = Button(file_display_frame, text="Choose Directory", command=choose_directory)
choose_button.pack(pady=10)
read_button = Button(file_display_frame, text="Read Images", command=read_images)
read_button.pack(pady=10)
switch_button = Button(file_display_frame, text="Switch to Gallery View", command=switch_view)
switch_button.pack(pady=10)
# Gallery/Slideshow View
image_display_frame = Frame(root)
display_images()
root.mainloop()