tommyyu 发表于 2024-2-17 11:43:29

清風 发表于 2024-2-17 11:42
.......

要不自己写代码?现在 AI 的水平还无法解决一些高难度的问题。

sfqxx 发表于 2024-2-17 12:54:03

这个试试?

from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QProgressBar, QLineEdit, QLabel, QMessageBox
from PySide6.QtCore import QTimer, Qt
import sys

class WelcomeWindow(QMainWindow):
    def __init__(self):
      super().__init__()
      self.setWindowTitle("欢迎")
      self.setGeometry(100, 100, 280, 100)
      self.progressBar = QProgressBar(self)
      self.progressBar.setGeometry(50, 50, 200, 30)
      self.initUI()

    def initUI(self):
      self.timer = QTimer(self)
      self.timer.timeout.connect(self.handleProgress)
      self.timer.start(100)
      self.show()

    def handleProgress(self):
      currentValue = self.progressBar.value()
      if currentValue < 100:
            currentValue += 1
            self.progressBar.setValue(currentValue)
      else:
            self.timer.stop()
            self.openLoginWindow()

    def openLoginWindow(self):
      self.loginWindow = LoginWindow(self)
      self.loginWindow.show()

class LoginWindow(QMainWindow):
    def __init__(self, parent=None):
      super().__init__(parent)
      self.attempts = 0
      self.setWindowTitle("登录")
      self.setGeometry(100, 100, 280, 100)
      layout = QVBoxLayout()
      self.label = QLabel("请输入密码:")
      self.lineEdit = QLineEdit()
      self.loginButton = QPushButton("登录")
      self.loginButton.clicked.connect(self.checkPassword)
      layout.addWidget(self.label)
      layout.addWidget(self.lineEdit)
      layout.addWidget(self.loginButton)
      centralWidget = QWidget()
      centralWidget.setLayout(layout)
      self.setCentralWidget(centralWidget)

    def checkPassword(self):
      password = self.lineEdit.text()
      if password == "correct":# 假设"correct"是正确的密码
            self.parent().close()# 关闭欢迎窗体
            self.close()# 关闭登录窗体
            self.mainWindow = MainWindow()# 打开主窗体
            self.mainWindow.show()
      else:
            self.attempts += 1
            QMessageBox.warning(self, "错误", "密码错误!")
            if self.attempts >= 3:
                QApplication.quit()

class MainWindow(QMainWindow):
    def __init__(self):
      super().__init__()
      self.setWindowTitle("主窗体")
      self.setGeometry(100, 100, 400, 300)
      layout = QVBoxLayout()
      for i in range(12):
            button = QPushButton(f"按钮 {i+1}")
            layout.addWidget(button)
      centralWidget = QWidget()
      centralWidget.setLayout(layout)
      self.setCentralWidget(centralWidget)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    welcomeWindow = WelcomeWindow()
    sys.exit(app.exec_())

清風 发表于 2024-2-17 14:11:23

sfqxx 发表于 2024-2-17 12:54
这个试试?

AI没懂的我意思    我也迷糊了
页: 1 [2]
查看完整版本: 求助~~