当然可以帮你写这段代码!下面是使用PySide6实现你描述的功能的代码:
import sys
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QProgressBar, QVBoxLayout, QWidget
class WelcomeWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("欢迎窗体")
self.resize(1400, 900)
self.center_window()
self.background_label = QLabel(self)
self.background_label.setPixmap("background.jpg") # 替换为你自己的背景图片
self.background_label.setAlignment(Qt.AlignCenter)
self.welcome_label = QLabel("欢迎", self)
self.welcome_label.setStyleSheet("font-size: 36px") # 设置标语的样式
self.welcome_label.setAlignment(Qt.AlignCenter)
self.progress_bar = QProgressBar(self)
self.progress_bar.setStyleSheet("""
QProgressBar {
text-align: center;
}
""")
self.progress_bar.setGeometry(200, 800, 1000, 40)
self.progress_bar.setRange(0, 100)
self.progress_bar.setValue(0)
self.layout = QVBoxLayout()
self.layout.addWidget(self.welcome_label)
self.layout.addWidget(self.progress_bar)
widget = QWidget()
widget.setLayout(self.layout)
self.setCentralWidget(widget)
self.show()
def center_window(self):
screen = QApplication.primaryScreen().geometry()
size = self.geometry()
self.move((screen.width() - size.width()) // 2, (screen.height() - size.height()) // 2)
class LoginWindow(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("登录窗体")
self.resize(400, 300)
self.center_window()
layout = QVBoxLayout()
# 添加用户名和密码输入框以及登录按钮
# ...
self.setLayout(layout)
def center_window(self):
screen = QApplication.primaryScreen().geometry()
size = self.geometry()
self.move((screen.width() - size.width()) // 2, (screen.height() - size.height()) // 2)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("主窗体")
self.resize(1400, 900)
self.center_window()
layout = QVBoxLayout()
# 添加按钮
# ...
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
self.show()
def center_window(self):
screen = QApplication.primaryScreen().geometry()
size = self.geometry()
self.move((screen.width() - size.width()) // 2, (screen.height() - size.height()) // 2)
if __name__ == "__main__":
app = QApplication(sys.argv)
welcome_window = WelcomeWindow()
login_window = LoginWindow(welcome_window)
main_window = MainWindow()
sys.exit(app.exec())
这段代码创建了三个窗口类分别表示欢迎窗体、登录窗体和主窗体。你可以根据需要进一步完善每个窗体的布局和功能。注意,你需要将背景图片文件名替换为你自己的图片文件名,并根据需求添加用户名、密码输入框以及按钮。希望能对你有所帮助!
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |