11import asyncio
22import os .path
33import sys
4- from PyQt5 .QtWidgets import QApplication , QWidget , QVBoxLayout , QHBoxLayout , QLineEdit , QPushButton , QLabel , QTextEdit , \
5- QComboBox , QMessageBox , QDialog
6- from PyQt5 .QtGui import QFont , QPalette , QColor , QIcon
4+
75from PyQt5 .QtCore import Qt
6+ from PyQt5 .QtGui import QFont , QPalette , QColor , QIcon
7+ from PyQt5 .QtWidgets import QApplication , QWidget , QVBoxLayout , QHBoxLayout , QLineEdit , QPushButton , QLabel , \
8+ QMessageBox , QDialog
89from qasync import QEventLoop
910
11+
1012class MyApplog (QDialog ):
1113 def __init__ (self ):
1214 super ().__init__ ()
@@ -20,37 +22,76 @@ def __init__(self):
2022 def initUI (self ):
2123 # 禁用默认的窗口框架
2224 self .setWindowFlags (Qt .FramelessWindowHint )
23-
25+
26+ # 设置窗口背景为白色
27+ self .setStyleSheet ("""
28+ QDialog {
29+ background-color: #ffffff;
30+ border-radius: 10px;
31+ }
32+ """ )
33+
2434 # 设置窗口属性
25- self .setWindowTitle ('賬號登錄' ) # 这个标题现在只用于任务栏显示
35+ self .setWindowTitle ('賬號登錄' )
36+ self .setFixedSize (400 , 300 ) # 固定窗口大小
37+
38+ # 创建主容器(浅灰色-白色面板,带圆角)
39+ main_container = QWidget ()
40+ main_container .setStyleSheet ("""
41+ QWidget {
42+ background-color: #f8f9fa;
43+ border-radius: 10px;
44+ }
45+ """ )
46+
2647 # 创建整体布局
27- main_layout = QVBoxLayout ()
48+ main_layout = QVBoxLayout (main_container )
49+ main_layout .setContentsMargins (20 , 20 , 20 , 20 )
50+ main_layout .setSpacing (15 )
2851
2952 # 创建自定义标题栏
3053 title_bar = QHBoxLayout ()
31- self .title_label = QLabel ("Facebook登錄" , self ) # 自定义标题文本
32- self .title_label .setFont (QFont ("微軟雅黑" , 12 , QFont .Bold ))
33- self .setFixedSize (350 , 0 ) # 设置窗口的固定大小
54+ title_bar .setContentsMargins (0 , 0 , 0 , 0 )
55+ title_bar .setSpacing (8 ) # 按钮之间的间距
56+
57+ self .title_label = QLabel ("Facebook 登錄" )
58+ self .title_label .setFont (QFont ("微軟雅黑" , 14 , QFont .Bold ))
59+ self .title_label .setStyleSheet ("color: #82c3ed; background: transparent;" )
3460 title_bar .addWidget (self .title_label )
3561 title_bar .addStretch (1 )
3662
37- # 添加关闭按钮到标题栏
38- close_button = QPushButton ("-" ) # 改变按钮文本为减号表示最小化
39- close_button .setFont (QFont ("微軟雅黑" , 12 ))
40- close_button .setFixedSize (24 , 24 )
41- close_button .clicked .connect (self .showMinimized ) # 连接到最小化方法
42- title_bar .addWidget (close_button )
43- # 添加关闭按钮到标题栏
44- close_button = QPushButton ("×" )
45- close_button .setFont (QFont ("微軟雅黑" , 12 ))
46- close_button .setFixedSize (24 , 24 )
63+ # 添加最小化按钮(蓝色圆圈)
64+ min_button = QPushButton ("" )
65+ min_button .setFixedSize (12 , 12 )
66+ min_button .setStyleSheet ("""
67+ QPushButton {
68+ background-color: #4fc3f7;
69+ border-radius: 6px;
70+ border: none;
71+ }
72+ QPushButton:hover {
73+ background-color: #29b6f6;
74+ }
75+ """ )
76+ min_button .clicked .connect (self .showMinimized )
77+ title_bar .addWidget (min_button )
78+
79+ # 添加关闭按钮(绿色圆圈)
80+ close_button = QPushButton ("" )
81+ close_button .setFixedSize (12 , 12 )
82+ close_button .setStyleSheet ("""
83+ QPushButton {
84+ background-color: #66bb6a;
85+ border-radius: 6px;
86+ border: none;
87+ }
88+ QPushButton:hover {
89+ background-color: #4caf50;
90+ }
91+ """ )
4792 close_button .clicked .connect (self .close )
4893 title_bar .addWidget (close_button )
49- close_button .setStyleSheet ("""
50- QPushButton:hover {
51- background-color: red;
52- }
53- """ )
94+
5495 # 将标题栏添加到主布局
5596 main_layout .addLayout (title_bar )
5697 login_name = ''
@@ -60,47 +101,90 @@ def initUI(self):
60101 login = file .read ().split ("|+|" )
61102 login_name = login [0 ].strip ('' )
62103 login_pass = login [1 ].strip ('' )
63- print (login_name ,login_pass )
104+ print (login_name , login_pass )
64105
65- # 创建三个输入框
66- self .txt_username = QLineEdit (self )
106+ # Facebook賬號输入区域
107+ account_label = QLabel ("Facebook賬號:" )
108+ account_label .setStyleSheet ("color: #64748b; font-size: 12px;" )
109+ account_label .setFont (QFont ("微軟雅黑" , 11 ))
110+ main_layout .addWidget (account_label )
111+
112+ self .txt_username = QLineEdit ()
67113 self .txt_username .setText (login_name )
68114 self .txt_username .setPlaceholderText ("請輸入賬號..." )
69- self .txt_password = QLineEdit (self )
115+ self .txt_username .setStyleSheet ("""
116+ QLineEdit {
117+ background-color: #ffffff;
118+ border: 1px solid #e0e0e0;
119+ border-radius: 5px;
120+ padding: 8px;
121+ font-size: 12px;
122+ color: #64748b;
123+ }
124+ QLineEdit:focus {
125+ border: 1px solid #82c3ed;
126+ }
127+ """ )
128+ main_layout .addWidget (self .txt_username )
129+
130+ # Facebook密碼输入区域
131+ password_label = QLabel ("Facebook密碼:" )
132+ password_label .setStyleSheet ("color: #64748b; font-size: 12px;" )
133+ password_label .setFont (QFont ("微軟雅黑" , 11 ))
134+ main_layout .addWidget (password_label )
135+
136+ self .txt_password = QLineEdit ()
70137 self .txt_password .setText (login_pass )
71138 self .txt_password .setPlaceholderText ("請輸入密碼..." )
72- main_layout .addWidget (QLabel ("Facebook賬號:" ))
73- main_layout .addWidget (self .txt_username )
74- main_layout .addWidget (QLabel ("Facebook密碼:" ))
139+ self .txt_password .setEchoMode (QLineEdit .Password ) # 密码模式
140+ self .txt_password .setStyleSheet ("""
141+ QLineEdit {
142+ background-color: #ffffff;
143+ border: 1px solid #e0e0e0;
144+ border-radius: 5px;
145+ padding: 8px;
146+ font-size: 12px;
147+ color: #64748b;
148+ }
149+ QLineEdit:focus {
150+ border: 1px solid #82c3ed;
151+ }
152+ """ )
75153 main_layout .addWidget (self .txt_password )
76154
77- # 创建水平布局用于放置按钮并居中
78- button_layout = QHBoxLayout ()
79- button_layout .addStretch (1 ) # 添加伸缩量使得按钮居中
80- self .button = QPushButton ('確定' , self )
81- self .button .setFixedSize (60 , 35 ) # 设置按钮大小
155+ # 添加弹性空间
156+ main_layout .addStretch (1 )
157+
158+ # 创建确认按钮(全宽)
159+ self .button = QPushButton ('確定' )
160+ self .button .setFixedHeight (40 )
82161 self .button .setStyleSheet ("""
83162 QPushButton {
84- border-radius: 15px;
85- background-color: #90EE90;
86- font-size: 16px;
163+ border-radius: 5px;
164+ background-color: #72bade;
165+ color: white;
166+ font-size: 14px;
87167 font-weight: bold;
168+ border: none;
169+ padding: 10px;
88170 }
89171 QPushButton:hover {
90- background-color: #7FFFD4;
172+ background-color: #4fa3ff;
173+ }
174+ QPushButton:pressed {
175+ background-color: #3d8fff;
91176 }
92177 """ )
93- button_layout .addWidget (self .button )
94- button_layout .addStretch (1 ) # 添加伸缩量使得按钮居中
95-
96- # 将按钮布局添加到主布局
97- main_layout .addLayout (button_layout )
178+ self .button .setFont (QFont ("微軟雅黑" , 12 , QFont .Bold ))
179+ main_layout .addWidget (self .button )
98180
99181 # 连接按钮点击事件到处理函数
100182 self .button .clicked .connect (self .on_click )
101183
102- # 设置布局
103- self .setLayout (main_layout )
184+ # 设置主窗口布局
185+ window_layout = QVBoxLayout (self )
186+ window_layout .setContentsMargins (0 , 0 , 0 , 0 )
187+ window_layout .addWidget (main_container )
104188
105189 # 显示窗口
106190 self .show ()
@@ -174,22 +258,22 @@ def win_main():
174258 if not app :
175259 app = QApplication (sys .argv )
176260
177- # 设置应用程序的样式
261+ # 设置应用程序的样式(浅色主题)
178262 app .setStyle ('Fusion' )
179263 palette = QPalette ()
180- palette .setColor (QPalette .Window , QColor (53 , 53 , 53 ))
181- palette .setColor (QPalette .WindowText , Qt . white )
182- palette .setColor (QPalette .Base , QColor (25 , 25 , 25 ))
183- palette .setColor (QPalette .AlternateBase , QColor (53 , 53 , 53 ))
264+ palette .setColor (QPalette .Window , QColor (255 , 255 , 255 ))
265+ palette .setColor (QPalette .WindowText , QColor ( 51 , 51 , 51 ) )
266+ palette .setColor (QPalette .Base , QColor (255 , 255 , 255 ))
267+ palette .setColor (QPalette .AlternateBase , QColor (248 , 249 , 250 ))
184268 palette .setColor (QPalette .ToolTipBase , Qt .white )
185- palette .setColor (QPalette .ToolTipText , Qt .white )
186- palette .setColor (QPalette .Text , Qt . white )
187- palette .setColor (QPalette .Button , QColor (53 , 53 , 53 ))
269+ palette .setColor (QPalette .ToolTipText , Qt .black )
270+ palette .setColor (QPalette .Text , QColor ( 51 , 51 , 51 ) )
271+ palette .setColor (QPalette .Button , QColor (99 , 181 , 255 ))
188272 palette .setColor (QPalette .ButtonText , Qt .white )
189273 palette .setColor (QPalette .BrightText , Qt .red )
190- palette .setColor (QPalette .Link , QColor (42 , 130 , 218 ))
191- palette .setColor (QPalette .Highlight , QColor (42 , 130 , 218 ))
192- palette .setColor (QPalette .HighlightedText , Qt .black )
274+ palette .setColor (QPalette .Link , QColor (130 , 195 , 237 ))
275+ palette .setColor (QPalette .Highlight , QColor (130 , 195 , 237 ))
276+ palette .setColor (QPalette .HighlightedText , Qt .white )
193277 app .setPalette (palette )
194278 app .setFont (QFont ("微軟雅黑" , 10 ))
195279 loop = QEventLoop (app )
0 commit comments