-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainExplain.py
More file actions
76 lines (51 loc) · 2.47 KB
/
mainExplain.py
File metadata and controls
76 lines (51 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Import the tkinter library and give it a shorter name "tk"
# Tkinter is used for creating graphical (GUI) applications in Python.
import tkinter as tk
# Import Image and ImageTk from the Pillow (PIL) library.
# Image lets us open and edit image files.
# ImageTk lets us display those images inside Tkinter.
from PIL import Image, ImageTk
# Import the random module to generate random numbers (for random spider positions).
import random
# Create the main application window (the root window).
root = tk.Tk()
# Make the window take up the entire screen (full screen mode).
root.attributes('-fullscreen', True)
# Keep the window always on top of all other windows.
root.attributes('-topmost', True)
# Make all black areas in the window transparent.
# ⚠️ This only works on Windows — not macOS or Linux.
root.attributes('-transparentcolor', 'black')
# Get the width of the screen (in pixels).
w = root.winfo_screenwidth()
# Get the height of the screen (in pixels).
h = root.winfo_screenheight()
# Create a canvas — a blank area where we can draw shapes or display images.
# It covers the entire screen (width = w, height = h),
# has a black background, and no border highlight.
canvas = tk.Canvas(root, width=w, height=h, bg='black', highlightthickness=0)
# Add the canvas to the window so it becomes visible.
canvas.pack()
# Open the image file "spider.png" using Pillow.
img = Image.open("spider.png")
# Convert the opened image into a format Tkinter can display.
spider_img = ImageTk.PhotoImage(img)
# Define a function that adds a spider image at a random position on the screen.
def add_spider():
# Pick a random x-coordinate between 0 and the screen width.
x = random.randint(0, w)
# Pick a random y-coordinate between 0 and the screen height.
y = random.randint(0, h)
# Place the spider image at the random (x, y) position on the canvas.
canvas.create_image(x, y, image=spider_img)
# Schedule this function to run again after 500 milliseconds (0.5 seconds).
# This makes new spiders keep appearing over time.
root.after(500, add_spider)
# Disable the close button (the “X”) so the user cannot close the window normally.
# lambda: None means “do nothing” when the close event is triggered.
root.protocol('WM_DELETE_WINDOW', lambda: None)
# Start the process of adding spiders repeatedly.
add_spider()
# Start Tkinter’s main event loop.
# This keeps the window open and waits for events (like time delays or user actions).
root.mainloop()