CV_AG/loadingscreen2.py

66 lines
1.7 KiB
Python

import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk
import time
import threading
def start_loading():
for i in range(101): # 0 to 100%
time.sleep(0.4) # 0.4s * 100 = 40 seconds
progress_var.set(i)
progress_bar.update_idletasks()
root.destroy()
# Set up full-screen window
root = tk.Tk()
root.title("Starting Up")
root.attributes('-fullscreen', True)
# Get screen size
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
# Load and resize the background image
try:
bg_img = Image.open("comicrobodog.png") # Replace with your image
bg_img = bg_img.resize((screen_width, screen_height), Image.ANTIALIAS)
bg_photo = ImageTk.PhotoImage(bg_img)
# Set as background using a label
bg_label = tk.Label(root, image=bg_photo)
bg_label.place(x=0, y=0, relwidth=1, relheight=1)
except Exception as e:
print("Error loading background image:", e)
root.configure(bg='black') # Fallback
# Overlay content frame (transparent background)
overlay = tk.Frame(root, bg='', padx=20, pady=20)
overlay.place(relx=0.5, rely=0.5, anchor='center')
# Message label
label = tk.Label(
overlay,
text="Computer Vision Vignette is Starting Up",
font=("Helvetica", 32, "bold"),
fg="white"
)
label.pack(pady=10)
# Progress bar
progress_var = tk.IntVar()
progress_bar = ttk.Progressbar(
overlay,
maximum=100,
variable=progress_var,
length=800
)
progress_bar.pack(pady=20)
# Start the progress in a thread
threading.Thread(target=start_loading, daemon=True).start()
# Close on ESC
root.bind("<Escape>", lambda e: root.destroy())
root.mainloop()