-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (41 loc) · 1.17 KB
/
Copy pathmain.py
File metadata and controls
49 lines (41 loc) · 1.17 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
"""
===========================
@Time : 2024/9/15 下午6:40
@Author : Entropy.Xu
@File : main.py
@Software: PyCharm
============================
"""
# main.py
import sys
import os
from PySide6.QtWidgets import QApplication
from PySide6.QtGui import QIcon
from main_window import MainWindow
def resource_path(relative_path):
"""获取资源文件的绝对路径"""
if getattr(sys, 'frozen', False):
# Nuitka 或 PyInstaller 打包后
base_path = sys._MEIPASS
else:
# 未打包,正常运行
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def main():
app = QApplication(sys.argv)
# 设置应用程序图标
icon_path = resource_path("resources/icon.ico")
app.setWindowIcon(QIcon(icon_path))
# 加载样式表
style_path = resource_path("styles/style.qss")
if os.path.exists(style_path):
with open(style_path, "r", encoding="utf-8") as f:
app.setStyleSheet(f.read())
else:
print(f"样式表未找到:{style_path}")
# 创建并显示主窗口
window = MainWindow()
window.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()