如何使用按钮更改主窗口并从另一个窗口运行事件 Pyside6

问题描述 投票:0回答:1

我想通过单击按钮更改主窗口,但是当主窗口更改时,事件不会运行。

两个窗口都已在 qt Designer 中创建 这是代码:

from PySide6.QtWidgets import *
from PySide6.QtWidgets import QPushButton
from PySide6.QtCore import  QObject
from PySide6.QtCore import  QCoreApplication
from PySide6.QtCore import *
from PySide6.QtGui import *

from PySide6 import QtWidgets, QtCore, QtGui
from ui_app import Ui_MainWindow
from ui_menu import Ui_MainWindow1
import sys

class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("Login")

        self.pushButton.clicked.connect(self.trocarpag)

    def trocarpag(self):
        if self.textuser.toPlainText() == "" :
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Warning)
            msg.setText("Preencha o Username!!!")
            msg.exec()
        elif self.textpass.toPlainText() == "" :
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Warning)
            msg.setText("Preencha a Password!!!")
            msg.exec()
        else:
            ###Change the Main Window####`
             self.ui = Ui_MainWindow1()
             self.ui.setupUi(self)
            
if __name__ =="__main__":
    app = QApplication()
    window = MainWindow()
    window.show()
    app.exec()
python pyqt pyside6
1个回答
0
投票

一行代码

self.ui = Ui_MainWindow1()
在类
window
的对象
MainWindow
中创建一个成员变量。没有代码可以替换当前窗口中的小部件或显示新窗口。

© www.soinside.com 2019 - 2024. All rights reserved.