Files
NexusLauncher/ui/splash_screen.py
2025-11-23 20:41:50 +08:00

139 lines
4.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
启动画面 - 使用customtkinter实现带淡入淡出动画
"""
import customtkinter as ctk
class SplashScreen(ctk.CTkToplevel):
"""启动画面 - 扁平化设计,带动画特效"""
def __init__(self, parent):
super().__init__(parent)
# 无边框窗口
self.overrideredirect(True)
# 窗口大小和位置(更扁平)
width = 500
height = 160
screen_width = self.winfo_screenwidth()
screen_height = self.winfo_screenheight()
x = (screen_width - width) // 2
y = (screen_height - height) // 2
self.geometry(f"{width}x{height}+{x}+{y}")
# 背景色 - 深色
bg_color = "#0d1117"
border_color = "#58a6ff"
# 设置窗口背景为边框颜色,创造边框效果
self.configure(fg_color=border_color)
# 主框架带圆角通过padding创造边框效果
main_frame = ctk.CTkFrame(
self,
fg_color=bg_color,
corner_radius=10
)
# 增大padding让圆角更明显
main_frame.pack(expand=True, fill="both", padx=2.5, pady=2.5)
# 内容容器
content_frame = ctk.CTkFrame(main_frame, fg_color="transparent")
content_frame.pack(expand=True, fill="both", padx=20, pady=15)
# 标题 - 使用更酷的字体和渐变色效果
title_frame = ctk.CTkFrame(content_frame, fg_color="transparent")
title_frame.pack(pady=(10, 5))
self.title_label = ctk.CTkLabel(
title_frame,
text="⚡ NEXUS LAUNCHER",
font=ctk.CTkFont(size=32, weight="bold", family="Consolas"),
text_color="#58a6ff"
)
self.title_label.pack()
# 副标题 - 科技感
self.subtitle_label = ctk.CTkLabel(
content_frame,
text="[ INITIALIZING SYSTEM ]",
font=ctk.CTkFont(size=11, family="Consolas"),
text_color="#8b949e"
)
self.subtitle_label.pack(pady=(0, 15))
# 进度条容器
progress_container = ctk.CTkFrame(content_frame, fg_color="transparent")
progress_container.pack(fill="x", pady=(0, 10))
# 进度条 - 更粗,带发光效果
self.progress = ctk.CTkProgressBar(
progress_container,
width=440,
height=12,
mode='indeterminate',
progress_color="#58a6ff",
fg_color="#161b22",
border_width=0,
corner_radius=6
)
self.progress.pack()
self.progress.start()
# 状态文本 - 动画效果
self.status_label = ctk.CTkLabel(
content_frame,
text="Loading modules...",
font=ctk.CTkFont(size=9, family="Consolas"),
text_color="#6e7681"
)
self.status_label.pack()
# 置顶
self.attributes('-topmost', True)
# 初始透明度动画
self.alpha = 0.0
self.attributes('-alpha', self.alpha)
self._fade_in()
self.update()
def _fade_in(self):
"""淡入动画"""
if self.alpha < 1.0:
self.alpha += 0.1
self.attributes('-alpha', self.alpha)
self.after(20, self._fade_in)
def _fade_out(self, callback):
"""淡出动画"""
if self.alpha > 0.0:
self.alpha -= 0.15
self.attributes('-alpha', self.alpha)
self.after(20, lambda: self._fade_out(callback))
else:
callback()
def update_status(self, message):
"""更新状态信息"""
try:
self.status_label.configure(text=message)
self.update()
except:
pass
def close(self):
"""关闭启动画面(带淡出动画)"""
try:
self.progress.stop()
self._fade_out(self.destroy)
except:
try:
self.destroy()
except:
pass