-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTkLoading.py
More file actions
64 lines (56 loc) · 2.66 KB
/
Copy pathCTkLoading.py
File metadata and controls
64 lines (56 loc) · 2.66 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
import customtkinter as ctk
import math
class LoadingAnimation:
def __init__(self, root):
self.root = root
self.window = ctk.CTkToplevel(root)
self.window.overrideredirect(True)
self.window.attributes("-alpha", 0.5)
self.window.attributes("-topmost", True)
# 设置窗口大小
self.window_width = 200
self.window_height = 200
self.center_window()
# 创建 Canvas 组件
self.canvas = ctk.CTkCanvas(self.window, width=self.window_width, height=self.window_height,bg="#CFCFCF",highlightthickness=0)
self.canvas.pack(fill="both", expand=True)
# 圆圈参数
self.angle = 0
self.radius = 50
self.center = (self.window_width // 2, self.window_height // 2)
self.line_length = 20
self.lines = []
self.create_loading_animation()
self.animate()
self.window.grab_set()
def center_window(self):
screen_width = self.window.winfo_screenwidth()
screen_height = self.window.winfo_screenheight()
x = (screen_width - self.window_width) // 2
y = (screen_height - self.window_height) // 2
self.window.geometry(f"{self.window_width}x{self.window_height}+{x}+{y}")
def create_loading_animation(self):
for i in range(12):
angle = i * 30
x1 = self.center[0] + self.radius * math.cos(math.radians(angle))
y1 = self.center[1] + self.radius * math.sin(math.radians(angle))
x2 = self.center[0] + (self.radius - self.line_length) * math.cos(math.radians(angle))
y2 = self.center[1] + (self.radius - self.line_length) * math.sin(math.radians(angle))
line = self.canvas.create_line(x1, y1, x2, y2, fill="yellow", width=3)
self.lines.append(line)
def animate(self):
self.angle += 10
if self.angle >= 360:
self.angle = 0
for i, line in enumerate(self.lines):
self.canvas.delete(line)
angle = (i * 30 + self.angle) % 360
x1 = self.center[0] + self.radius * math.cos(math.radians(angle))
y1 = self.center[1] + self.radius * math.sin(math.radians(angle))
x2 = self.center[0] + (self.radius - self.line_length) * math.cos(math.radians(angle))
y2 = self.center[1] + (self.radius - self.line_length) * math.sin(math.radians(angle))
self.lines[i] = self.canvas.create_line(x1, y1, x2, y2, fill="black", width=3)
self.window.after(100, self.animate)
def close(self):
self.window.grab_release()
self.window.destroy()