[Tutor] My first program doesn't seem to do anything -- followup

carrfamily at mindspring.com carrfamily at mindspring.com
Sun Apr 28 11:14:26 EDT 2024



I asked an AI to write a python program that would scroll through a folder
of pictures, and to display each .jpg it finds for 15 seconds.  I'm working
in Visual Studio Code. After finally getting it error-free, I ran it but no
window opens.  Nothing seems to happen.  Please advise.  Here's the program.

 

# This is pix.py

# Python program that will walk through a folder of .jpg files and display
each one for 15 seconds

import os

import time

import tkinter as tk

from PIL import Image, ImageTk

folder_path = "c:/Users/Tim Carr/Pictures/_Parents"

def display_images(folder_path):

    # Create a Tkinter window

    window = tk.Tk()

    window.title("Image Viewer")

 

    # Get a list of all .jpg files in the folder

    image_files = [f for f in os.listdir(folder_path) if f.endswith(".jpg")]

 

    # Display each image for 15 seconds

    for image_file in image_files:

        image_path = os.path.join(folder_path, image_file)

        image = Image.open(image_path)

        photo = ImageTk.PhotoImage(image)

 

        # Create a label to display the image

        label = tk.Label(window, image=photo)

        label.pack()

 

        # Display the image for 15 seconds

        window.after(15000, label.destroy)

        window.mainloop()

 

Tim Carr

Benton House Room 208

2711 Lawrenceville Hwy

Decatur GA 30033

678.395.3551

 



More information about the Tutor mailing list