AI写代码真的可以大大节省时间啦

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QFormLayout
class LoginWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 设置窗口标题和大小
self.setWindowTitle('登录')
self.setFixedSize(300, 150)
# 创建标签和文本框
self.username_label = QLabel('用户名:')
self.username_text = QLineEdit()
self.password_label = QLabel('密码:')
self.password_text = QLineEdit()
self.password_text.setEchoMode(QLineEdit.Password)
# 创建登录和注册按钮
self.login_button = QPushButton('登录')
self.register_button = QPushButton('注册')
# 创建布局并添加部件
vbox = QVBoxLayout()
hbox1 = QHBoxLayout()
hbox1.addWidget(self.username_label)
hbox1.addWidget(self.username_text)
hbox2 = QHBoxLayout()
hbox2.addWidget(self.password_label)
hbox2.addWidget(self.password_text)
hbox3 = QHBoxLayout()
hbox3.addWidget(self.login_button)
hbox3.addWidget(self.register_button)
vbox.addLayout(hbox1)
vbox.addLayout(hbox2)
vbox.addLayout(hbox3)
self.setLayout(vbox)
# 连接登录和注册按钮的信号槽
self.login_button.clicked.connect(self.login)
self.register_button.clicked.connect(self.register)
# 设置样式表
self.setStyleSheet("""
QWidget {
background-color: #f0f0f0;
}
QLabel {
font: bold 16px;
color: #333333;
}
QLineEdit {
background-color: #ffffff;
border: 1px solid #cccccc;
border-radius: 3px;
font: 14px;
padding: 5px;
}
QPushButton {
background-color: #4CAF50;
color: #ffffff;
font: bold 16px;
border: none;
border-radius: 3px;
padding: 5px 10px;
}
QPushButton:hover {
background-color: #3e8e41;
}
""")
def login(self):
# 登录逻辑
print('登录')
def register(self):
# 注册逻辑
print('注册')
if __name__ == '__main__':
app = QApplication(sys.argv)
login_window = LoginWindow()
login_window.show()
sys.exit(app.exec_())
直接可以运行,关键是按钮还很好看

浙公网安备 33010602011771号