使用PyQt5

时间:2018-05-27 23:36:41

标签: python button pyqt5

这是我第一次在Python上使用PyQt5模块而且当我想添加打开文件并测试它的函数时我有这个错误它没有给我任何东西,只需重新启动shell并退出 这是我的代码

from PyQt5 import QtCore, QtGui, QtWidgets 
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog,QFileDialog, QPushButton

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(590, 531)
        self.AddPicBtn = QtWidgets.QPushButton(Form)
        self.AddPicBtn.setGeometry(QtCore.QRect(250, 480, 75, 23))
        self.AddPicBtn.setObjectName("AddPicBtn")
        self.AddPicBtn.clicked.connect(self.add)
        self.PredictBtn = QtWidgets.QPushButton(Form)
        self.PredictBtn.setGeometry(QtCore.QRect(340, 480, 75, 23))
        self.PredictBtn.setObjectName("PredictBtn")
        self.CancelBtn = QtWidgets.QPushButton(Form)
        self.CancelBtn.setGeometry(QtCore.QRect(430, 480, 75, 23))
        self.CancelBtn.setObjectName("CancelBtn")
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(70, 60, 431, 341))
        self.label.setText("")
        self.label.setObjectName("label")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def add(self):
        options = QFileDialog.Options()
        options |= QFileDialog.DontUseNativeDialog
        fileName, _ = QFileDialog.getOpenFileName(self,"QFileDialog.getOpenFileName()", "","All Files (*);;Python Files (*.py)", options=options)
        if fileName:
            print(fileName)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.AddPicBtn.setText(_translate("Form", "Ajouter.."))
        self.PredictBtn.setText(_translate("Form", "Predicter"))
        self.CancelBtn.setText(_translate("Form", "Annuler"))

0 个答案:

没有答案