- import time
- from PIL import Image
- import os
- import tempfile
- def show_image_temporary(image_path, display_time=30):
- # Open the image
- image = Image.open(image_path)
- # Create a temporary file to display the image
- temp_file, temp_path = tempfile.mkstemp(suffix='.png')
- os.close(temp_file) # Close the file descriptor
- # Save the image to the temporary file
- image.save(temp_path)
- # Open the temporary image, which should open it in the default viewer
- os.startfile(temp_path)
- # Wait for the specified display time
- time.sleep(display_time)
- # Attempt to remove the temporary file, hoping the viewer closes (may not work on all viewers)
- try:
- os.remove(temp_path)
- except Exception as e:
- print(f"Error removing temporary file: {e}")
- # Path to your image file
- image_path = "C:/Users/tycel/OneDrive/Pictures/AI/00003-1951429625.png"
- # Show the image for 30 seconds
- show_image_temporary(image_path, 30)