Skip to content

Commit db89f4f

Browse files
committed
refactor(FB_loginwin.py): 重构login窗口样式布局
1 parent dba9578 commit db89f4f

2 files changed

Lines changed: 128 additions & 145 deletions

File tree

facebook/FB.json

Lines changed: 0 additions & 82 deletions
This file was deleted.

facebook/FB_loginwin.py

Lines changed: 128 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLineEdit, QPushButton, QLabel, QTextEdit, \
55
QComboBox, QMessageBox, QDialog
66
from PyQt5.QtGui import QFont, QPalette, QColor, QIcon
7-
from PyQt5.QtCore import Qt
7+
from PyQt5.QtCore import Qt, pyqtSignal
88
from qasync import QEventLoop
99

1010
class MyApplog(QDialog):
11+
window_closed = pyqtSignal()
12+
1113
def __init__(self):
1214
super().__init__()
1315
icon_path = resource_path("Thcat.ico")
@@ -20,88 +22,151 @@ def __init__(self):
2022
def initUI(self):
2123
# 禁用默认的窗口框架
2224
self.setWindowFlags(Qt.FramelessWindowHint)
23-
24-
# 设置窗口属性
25-
self.setWindowTitle('賬號登錄') # 这个标题现在只用于任务栏显示
26-
# 创建整体布局
27-
main_layout = QVBoxLayout()
28-
29-
# 创建自定义标题栏
30-
title_bar = QHBoxLayout()
31-
self.title_label = QLabel("Facebook登錄", self) # 自定义标题文本
32-
self.title_label.setFont(QFont("微軟雅黑", 12, QFont.Bold))
33-
self.setFixedSize(350, 0) # 设置窗口的固定大小
34-
title_bar.addWidget(self.title_label)
35-
title_bar.addStretch(1)
36-
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)
47-
close_button.clicked.connect(self.close)
48-
title_bar.addWidget(close_button)
49-
close_button.setStyleSheet("""
50-
QPushButton:hover {
51-
background-color: red;
52-
}
53-
""")
54-
# 将标题栏添加到主布局
55-
main_layout.addLayout(title_bar)
25+
self.setWindowTitle('Facebook 登錄')
26+
27+
# 读取保存的登录信息
5628
login_name = ''
5729
login_pass = ''
5830
if os.path.exists('FBlogin.txt'):
5931
with open('FBlogin.txt', mode='r', newline='', encoding='utf-8') as file:
6032
login = file.read().split("|+|")
6133
login_name = login[0].strip('')
6234
login_pass = login[1].strip('')
63-
print(login_name,login_pass)
35+
print(login_name, login_pass)
6436

65-
# 创建三个输入框
37+
# 创建整体布局
38+
main_layout = QVBoxLayout()
39+
main_layout.setContentsMargins(30, 25, 30, 25)
40+
main_layout.setSpacing(20)
41+
42+
# 标题行(包含最小化、关闭按钮)
43+
title_row = QHBoxLayout()
44+
self.title_label = QLabel("Facebook登錄")
45+
self.title_label.setFont(QFont("微軟雅黑", 18, QFont.Bold))
46+
self.title_label.setStyleSheet("color: #333333;")
47+
title_row.addWidget(self.title_label)
48+
title_row.addStretch(1)
49+
50+
# 最小化按钮
51+
min_button = QPushButton("-", self)
52+
min_button.setFixedSize(24, 24)
53+
min_button.setFont(QFont("微軟雅黑", 8))
54+
min_button.clicked.connect(self.showMinimized)
55+
min_button.setStyleSheet("""
56+
QPushButton {
57+
background-color: transparent;
58+
border: 1px solid #ccc;
59+
border-radius: 12px;
60+
}
61+
QPushButton:hover {
62+
background-color: #f2b84b;
63+
}
64+
""")
65+
title_row.addWidget(min_button)
66+
67+
# 关闭按钮
68+
close_button = QPushButton("×", self)
69+
close_button.setFixedSize(24, 24)
70+
close_button.setFont(QFont("微軟雅黑", 8))
71+
close_button.clicked.connect(self.close)
72+
close_button.setStyleSheet("""
73+
QPushButton {
74+
background-color: transparent;
75+
border: 1px solid #ccc;
76+
border-radius: 12px;
77+
}
78+
QPushButton:hover {
79+
background-color: #ff4d4f;
80+
color: white;
81+
}
82+
""")
83+
title_row.addWidget(close_button)
84+
85+
main_layout.addLayout(title_row)
86+
87+
# 分隔线
88+
separator = QLabel()
89+
separator.setFixedHeight(1)
90+
separator.setStyleSheet("background-color: #e0e0e0;")
91+
main_layout.addWidget(separator)
92+
main_layout.addSpacing(5)
93+
94+
# 表单布局
95+
def add_row(label_text, widget):
96+
row = QVBoxLayout()
97+
row.setSpacing(6)
98+
lbl = QLabel(label_text)
99+
lbl.setFont(QFont("微軟雅黑", 10))
100+
row.addWidget(lbl)
101+
row.addWidget(widget)
102+
main_layout.addLayout(row)
103+
104+
# 创建输入框
66105
self.txt_username = QLineEdit(self)
67106
self.txt_username.setText(login_name)
68-
self.txt_username.setPlaceholderText("請輸入賬號...")
107+
self.txt_username.setPlaceholderText("請輸入帳號...")
108+
add_row("Facebook帳號:", self.txt_username)
109+
69110
self.txt_password = QLineEdit(self)
70111
self.txt_password.setText(login_pass)
71112
self.txt_password.setPlaceholderText("請輸入密碼...")
72-
main_layout.addWidget(QLabel("Facebook賬號:"))
73-
main_layout.addWidget(self.txt_username)
74-
main_layout.addWidget(QLabel("Facebook密碼:"))
75-
main_layout.addWidget(self.txt_password)
76-
77-
# 创建水平布局用于放置按钮并居中
78-
button_layout = QHBoxLayout()
79-
button_layout.addStretch(1) # 添加伸缩量使得按钮居中
113+
self.txt_password.setEchoMode(QLineEdit.Password)
114+
add_row("Facebook密碼:", self.txt_password)
115+
116+
main_layout.addSpacing(10)
117+
118+
# 确定按钮
80119
self.button = QPushButton('確定', self)
81-
self.button.setFixedSize(60, 35) # 设置按钮大小
82-
self.button.setStyleSheet("""
83-
QPushButton {
84-
border-radius: 15px;
85-
background-color: #90EE90;
86-
font-size: 16px;
87-
font-weight: bold;
120+
self.button.setFixedHeight(40)
121+
self.button.setObjectName("confirm")
122+
main_layout.addWidget(self.button)
123+
124+
# 设置布局
125+
self.setLayout(main_layout)
126+
127+
# 设置窗口大小
128+
self.setFixedSize(400, 320)
129+
130+
# 应用全局样式
131+
self.setStyleSheet("""
132+
QWidget {
133+
background-color: #fefbf8;
134+
}
135+
QLabel {
136+
color: #333333;
137+
background-color: transparent;
138+
}
139+
QLineEdit {
140+
padding: 8px;
141+
border: 1px solid #e0e0e0;
142+
border-radius: 6px;
143+
font-size: 14px;
144+
background: #ffffff;
145+
color: #333333;
146+
}
147+
QLineEdit:focus {
148+
border: 1px solid #1890ff;
149+
outline: none;
150+
}
151+
QPushButton#confirm {
152+
border-radius: 6px;
153+
background-color: #f2b84b;
154+
color: #ffffff;
155+
font-weight: bold;
156+
border: 0px;
157+
font-size: 14px;
88158
}
89-
QPushButton:hover {
90-
background-color: #7FFFD4;
159+
QPushButton#confirm:hover {
160+
background-color: #ffc107;
161+
}
162+
QPushButton#confirm:pressed {
163+
background-color: #cc9900;
91164
}
92165
""")
93-
button_layout.addWidget(self.button)
94-
button_layout.addStretch(1) # 添加伸缩量使得按钮居中
95-
96-
# 将按钮布局添加到主布局
97-
main_layout.addLayout(button_layout)
98166

99-
# 连接按钮点击事件到处理函数
167+
# 连接按钮点击事件
100168
self.button.clicked.connect(self.on_click)
101169

102-
# 设置布局
103-
self.setLayout(main_layout)
104-
105170
# 显示窗口
106171
self.show()
107172

0 commit comments

Comments
 (0)