由于某种原因,clicked.connect()方法不会等待点击,还会使我的小部件消失。
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form():
def __init__(self, nCode_analysis_set_up):
nCode_analysis_set_up.resize(300, 60)
nCode_analysis_set_up.setWindowFlags(nCode_analysis_set_up.windowFlags() | QtCore.Qt.MSWindowsFixedSizeDialogHint)
nCode_analysis_set_up.setWindowTitle("nCode analysis set-up")
self.importButton = QtWidgets.QPushButton(nCode_analysis_set_up)
self.importButton.setGeometry(QtCore.QRect(10, 10, 280, 40))
self.importButton.setText("Open import model")
self.importButton.clicked.connect(self.input_model(nCode_analysis_set_up))
def input_model(self,nCode_analysis_set_up):
fileName, _ = QtWidgets.QFileDialog.getOpenFileName(None, "Select model","","Input deck (*.inp)",".inp")
fileName = str(fileName)
if fileName:
nCode_analysis_set_up.resize(500, 150)
self.importButton.deleteLater()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
nCode_analysis_set_up = QtWidgets.QWidget()
ui = Ui_Form(nCode_analysis_set_up)
nCode_analysis_set_up.show()
sys.exit(app.exec_())
如果我注释掉click.connect方法,它会很好地工作,并显示我的单按钮形式。有人可以看到我在做什么错吗?