适合初学者的PYQt

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

我试图在 QDialog.it 显示对话框后显示 QMainwindow,当需要显示 QMainWindow 程序时不执行。帮助?

"""
#import QtData_Tree as DT  
import sys
import sqlite3
from PyQt5 import QtWidgets
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QMainWindow,QDialog,QApplication

class Welcom(QDialog):
    def __init__(self):
        super(Welcom,self).__init__()
        loadUi("Welcom.ui",self)
        self.setWindowTitle("Welcom")
        
class Login(QDialog):
    def __init__(self):
        super(Login,self).__init__()
        loadUi("Login.ui",self)
        #self.login_btn.clicked.connect(self.loaddata)
        self.password_input.setEchoMode(QtWidgets.QLineEdit.Password)
        self.back_btn.clicked.connect(goback)
        self.login_btn.clicked.connect(goDT)
        
class data_entery(QMainWindow):
    def __init__(self):
        super(data_entery,self).__init__()
        loadUi("QtData_Tree.ui",self)

def goDT():
    log=QtData_Tree()
    widget.addWidget(log)
    widget.setCurrentIndex(widget.currentIndex()+2)

   
app=QApplication(sys.argv)   
welcom_win=Welcom()
widget=QtWidgets.QStackedWidget()
widget.addWidget(welcom_win)
#widget.setFixedHeight(550)
#widget.setFixedWidth(450)
widget.show()
app.exec()

我为 QmainWindow 创建了一个新文件,它可以工作,但我在链接两个文件/程序时遇到问题

python python-3.x pyqt pyqt5
1个回答
0
投票
import sys
from PyQt5 import QtWidgets
from PyQt5.uic import loadUi

class Welcom(QtWidgets.QDialog):
    def __init__(self, parent=None):
        super(Welcom, self).__init__(parent)
        loadUi("Welcom.ui", self)
        self.setWindowTitle("Welcome")
        self.show()  # Show the welcome dialog

class Login(QtWidgets.QDialog):
    def __init__(self, parent=None):
        super(Login, self).__init__(parent)
        loadUi("Login.ui", self)
        self.password_input.setEchoMode(QtWidgets.QLineEdit.Password)
        self.back_btn.clicked.connect(self.goback)
        self.login_btn.clicked.connect(self.goDT)

    def goback(self):
        # Add logic to go back
        pass

    def goDT(self):
        self.accept()  # Close the login dialog

class DataEntry(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super(DataEntry, self).__init__(parent)
        loadUi("QtData_Tree.ui", self)

def main():
    app = QtWidgets.QApplication(sys.argv)
    welcom_win = Welcom()

    if welcom_win.exec_() == QtWidgets.QDialog.Accepted:
        login_win = Login()
        if login_win.exec_() == QtWidgets.QDialog.Accepted:
            main_win = DataEntry()
            main_win.show()
            sys.exit(app.exec_())

if __name__ == "__main__":
    main()
© www.soinside.com 2019 - 2024. All rights reserved.