如果条件为真,如何关闭当前窗口并打开新窗口(没有单击任何按钮)并再次运行洞脚本。我尝试了这么多方法,但没有成功。
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
.....
if __name__ == "__main__":
# print(deivce_data)
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
if deivce_data == data:
'''if this condition is true close the current window and run script again'''
发布于 2022-07-02 04:15:52
您可以通过控制QApplication()的执行句柄来做到这一点。
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
class Ui_MainWindow(QMainWindow):
def __init__(self):
super().__init__()
if __name__ == "__main__":
# print(deivce_data)
app1 = QApplication(sys.argv)
ui1 = Ui_MainWindow()
ui1.setWindowTitle("My App1")
ui1.show()
finish_app1 = app1.exec_()
if True:
'''if this condition is true close the current window and run script again'''
app2 = QApplication(sys.argv)
ui2 = Ui_MainWindow()
ui2.setWindowTitle("My App2")
ui2.show()
finish_app2 = app2.exec_()
handle_finish = finish_app2
else:
handle_finish = finish_app1
sys.exit(handle_finish)
希望这能有所帮助。
https://stackoverflow.com/questions/72557224
复制相似问题