pyqt5切换python版本_如何来回切换pyqt5对话框?

我想在两个对话框之间切换多次,但是我现在的代码只做了2次切换,然后就停止了。在问题(第二个对话框)

第二个对话到第一个对话(没有问题)

第一个对话框到第二个对话框(所以当我再次尝试转到第二个对话框时,代码停止运行)

我试着将可见性设置为True和False,而不是关闭对话框对话框.exec_()而不是对话框.exec()from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Dialog(object):

def setupUi(self, Dialog):

Dialog.setObjectName("Dialog")

Dialog.resize(633, 242)

self.pushButton = QtWidgets.QPushButton(Dialog)

self.pushButton.setGeometry(QtCore.QRect(120, 70, 401, 81))

self.pushButton.setObjectName("pushButton")

self.retranslateUi(Dialog)

QtCore.QMetaObject.connectSlotsByName(Dialog)

self.pushButton.clicked.connect(self.page_2)

def page_2(self):

start_D2()

def retranslateUi(self, Dialog):

_translate = QtCore.QCoreApplication.translate

Dialog.setWindowTitle(_translate("Dialog", "Dialog_1"))

self.pushButton.setText(_translate("Dialog", "Go to Second Page"))

class Ui_Dialog_2(object):

def setupUi(self, Dialog):

Dialog.setObjectName("Dialog")

Dialog.resize(633, 242)

self.pushButton = QtWidgets.QPushButton(Dialog)

self.pushButton.setGeometry(QtCore.QRect(120, 70, 401, 81))

self.pushButton.setObjectName("pushButton")

self.retranslateUi(Dialog)

QtCore.QMetaObject.connectSlotsByName(Dialog)

self.pushButton.clicked.connect(self.page_1)

def page_1(self):

start_D1()

def retranslateUi(self, Dialog):

_translate = QtCore.QCoreApplication.translate

Dialog.setWindowTitle(_translate("Dialog", "Dialog_2"))

self.pushButton.setText(_translate("Dialog", "Go to First Page"))

def start_D2():

try:

Dialog.close()

ui = Ui_Dialog_2()

ui.setupUi(Dialog_2)

Dialog_2.exec()

except Exception as e:

print(e)

def start_D1():

try:

Dialog_2.close()

ui = Ui_Dialog()

ui.setupUi(Dialog)

Dialog.exec()

except Exception as e:

print(e)

if __name__ == "__main__":

import sys

app = QtWidgets.QApplication(sys.argv)

Dialog = QtWidgets.QDialog()

Dialog_2 = QtWidgets.QDialog()

ui = Ui_Dialog()

ui.setupUi(Dialog)

Dialog.show()

sys.exit(app.exec_())

我需要的是每次点击按钮时都要切换对话框,而不仅仅是一两次。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值