from tkinter import * import random import math class Converter: def __init__(self): self.root = root self.windows = [] self.running = False self.screen_width = root.winfo_screenwidth() self.screen_height = root.winfo_screenheight() self.window_width = 250 self.window_height = 150 self.angle = 0 self.scale_direction = 1 Button(root, text="Start Demo", font=("Arial", 14, "bold"), command=self.start).pack(pady=20) root.bind_all("", self.kill) root.bind_all("", self.kill) # ---------------------- def start(self): if self.running: return self.running = True prompt = Toplevel() prompt.geometry("300x150+500+300") Label(prompt, text="Starting Demo...", font=("Arial", 14)).pack(expand=True) self.root.after(1000, lambda: prompt.destroy()) self.root.after(1000, self.spawn_grid) self.root.after(1500, self.animate) # ---------------------- # FILL ENTIRE SCREEN def spawn_grid(self): cols = self.screen_width // self.window_width + 1 rows = self.screen_height // self.window_height + 1 for row in range(rows): for col in range(cols): x = col * self.window_width y = row * self.window_height win = AnimatedWindow(x, y, self.window_width, self.window_height) self.windows.append(win) # ---------------------- # MAIN ANIMATION LOOP def animate(self): if not self.running: return self.angle += 0.03 for win in self.windows: win.update_motion(self.screen_width, self.screen_height, self.scale_direction) self.scale_direction *= -1 self.root.after(40, self.animate) # ---------------------- def kill(self, event=None): self.running = False for win in self.windows: win.destroy() self.windows.clear() print("Stopped safely.") # =================================================== class AnimatedWindow: def __init__(self, x, y, w, h): self.w = w self.h = h self.x = x self.y = y self.dx = random.choice([-3, -2, 2, 3]) self.dy = random.choice([-3, -2, 2, 3]) self.win = Toplevel() self.win.geometry(f"{w}x{h}+{x}+{y}") self.label = Label(self.win, text="Demo Window", font=("Arial", 12, "bold")) self.label.pack(expand=True, fill="both") # ---------------------- def update_motion(self, screen_w, screen_h, scale_dir): # Move self.x += self.dx self.y += self.dy # Bounce off edges if self.x <= 0 or self.x + self.w >= screen_w: self.dx *= -1 if self.y <= 0 or self.y + self.h >= screen_h: self.dy *= -1 # Resize smoothly self.w += scale_dir * 2 self.h += scale_dir * 2 if self.w < 150 or self.w > 350: self.w = max(150, min(self.w, 350)) # Flash random color color = "#%02x%02x%02x" % ( random.randint(0, 255), random.randint(0, 255), random.randint(0, 255) ) self.label.config(bg=color) self.win.geometry(f"{self.w}x{self.h}+{self.x}+{self.y}") # ---------------------- def destroy(self): self.win.destroy() # =================================================== if __name__ == "__main__": root = Tk() root.title("Advanced Animation Demo") Converter() root.mainloop()