PyQt窗口在启动后崩溃

时间:2018-03-19 13:49:57

标签: pyqt pyqt5

我正在尝试启动以下代码。 “应用程序”窗口打开,但只要单击该按钮,窗口就会崩溃。

import sys
from qtpy import QtWidgets
from src.ui.mainwindow import Ui_MainWindow
from src.Run_OMD_Process import run_omd

app = QtWidgets.QApplication(sys.argv)


class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent = None):
        super().__init__(parent)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setWindowTitle("OMD Tool")
        print("MainWindow")
        self.ui.pushButton.clicked.connect(self.onPushOmdButton)
        # self.ui.pushButton_2.clicked.connect(self.exitUi)

    def onPushOmdButton(self):
        self.ui.pushButton.clicked.connect(run_omd())


window = MainWindow()
window.show()
sys.exit(app.exec_())

2 个答案:

答案 0 :(得分:1)

当您将run_omd电话上的括号连接到onPushOmdButton中的按钮时,它已经崩溃了。

尝试:

self.ui.pushButton.clicked.connect(run_omd)

此方法也只是将按钮重新连接到其他功能。所以基本上,你必须点击两次按钮才能得到我相信你所追求的结果。我不确定这是不是你想要的。

答案 1 :(得分:0)

在这一点上,我同意MalloyDekacroix:

import sys
from pyqt import QtWidgets
from src.ui.mainwindow import Ui_MainWindow
from src.Run_OMD_Process import run_omd

app = QtWidgets.QApplication(sys.argv)


class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent = None):
        super().__init__(parent)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setWindowTitle("OMD Tool")
        print("Main`enter code here`Window")
        self.ui.pushButton.clicked.connect(self.onPushOmdButton)
        # self.ui.pushButton_2.clicked.connect(self.exitUi)

    def onPushOmdButton(self):
        // i.e. this could so something else. 
        // for instance, open a new window.
        // perform a calculation.
        // As your code I also feel requires the user to click again. 

window = MainWindow()
window.show()
sys.exit(app.exec_())