PYTHON 21
Untitled By tycel2004 on 5th February 2024 05:46:45 PM
  1. import time
  2. from PIL import Image
  3. import os
  4. import tempfile
  5.  
  6. def show_image_temporary(image_path, display_time=30):
  7.     # Open the image
  8.     image = Image.open(image_path)
  9.    
  10.     # Create a temporary file to display the image
  11.     temp_file, temp_path = tempfile.mkstemp(suffix='.png')
  12.     os.close(temp_file)  # Close the file descriptor
  13.    
  14.     # Save the image to the temporary file
  15.     image.save(temp_path)
  16.    
  17.     # Open the temporary image, which should open it in the default viewer
  18.     os.startfile(temp_path)
  19.    
  20.     # Wait for the specified display time
  21.     time.sleep(display_time)
  22.    
  23.     # Attempt to remove the temporary file, hoping the viewer closes (may not work on all viewers)
  24.     try:
  25.         os.remove(temp_path)
  26.     except Exception as e:
  27.         print(f"Error removing temporary file: {e}")
  28.  
  29. # Path to your image file
  30. image_path = "C:/Users/tycel/OneDrive/Pictures/AI/00003-1951429625.png"
  31.  
  32. # Show the image for 30 seconds
  33. show_image_temporary(image_path, 30)

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.