Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import random
- import time
- import ctypes
- import sys
- ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0)
- class FloatingLogo:
- def __init__(self, root):
- self.root = root
- self.root.overrideredirect(True)
- self.root.attributes('-topmost', True)
- self.root.wm_attributes("-transparentcolor", "white")
- self.canvas = tk.Canvas(root, bg='white', highlightthickness=0)
- self.canvas.pack(fill=tk.BOTH, expand=True)
- self.rect = self.canvas.create_rectangle(10, 10, 150, 80, fill='red', outline='black')
- self.text = self.canvas.create_text(80, 45, text="Привет", font=('Arial', 24, 'bold'))
- self.x = random.randint(0, root.winfo_screenwidth() - 160)
- self.y = random.randint(0, root.winfo_screenheight() - 90)
- self.dx = random.choice([-4, -3, 3, 4])
- self.dy = random.choice([-4, -3, 3, 4])
- self.root.geometry(f"160x90+{self.x}+{self.y}")
- self.animate()
- def animate(self):
- self.x += self.dx
- self.y += self.dy
- if self.x <= 0 or self.x >= self.root.winfo_screenwidth() - 160:
- self.dx = -self.dx
- self.change_color()
- if self.y <= 0 or self.y >= self.root.winfo_screenheight() - 90:
- self.dy = -self.dy
- self.change_color()
- self.root.geometry(f"+{self.x}+{self.y}")
- self.root.after(20, self.animate)
- def change_color(self):
- colors = ['red', 'green', 'blue', 'yellow', 'orange', 'purple', 'pink']
- new_color = random.choice(colors)
- self.canvas.itemconfig(self.rect, fill=new_color)
- def create_floating_window():
- root = tk.Tk()
- logo = FloatingLogo(root)
- root.mainloop()
- if __name__ == "__main__":
- import threading
- def create_window():
- create_floating_window()
- for i in range(500):
- threading.Thread(target=create_window).start()
- time.sleep(0.1)
- while True:
- time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement