0

I am trying to create desktop app. I have created a button using pyqt4 designer.Then converted .ui to .py file. Button which i have created should work as file picker. I am finding difficult to add file browser to that.Can any one help me regarding this.

Code i tried

def setupUi(self, WizardPage):
        WizardPage.setObjectName(_fromUtf8("WizardPage"))
        WizardPage.resize(636, 486)
        self.horizontalLayoutWidget = QtGui.QWidget(WizardPage)
        self.groupBox = QtGui.QGroupBox(self.horizontalLayoutWidget)
        self.groupBox.setObjectName(_fromUtf8("groupBox"))
        self.pushButton = QtGui.QPushButton(self.groupBox)
def retranslateUi(self, WizardPage):
    WizardPage.setWindowTitle(_translate("WizardPage", "WizardPage", None))
    self.groupBox.setTitle(_translate("WizardPage", "SOURCE", None))
    self.pushButton.setText(_translate("WizardPage", "Click Me!", None))
    self.pushButton.clicked.connect(self.pushButton_Clicked)

def pushButton_Clicked(self, WizardPage):
    filename = QtGui.QFileDialog.getOpenFileName(self)

Please guide me where i am going wrong?

1 Answer 1

3

First of all, never directly edit the .py file created by pyuic. Instead, import it into your main program, or (my preferred method, makes you more productive) use the uic module (imported from PyQt with from PyQt4 import uic.) ui = uic.loadUi('example.ui') will import the UI file.

However, in resolution of your problem you need to change some things.

openfile = QtGui.QFileDialog.getOpenFileName(self) # Filename line
f = open(openfile, 'r') # New line
data = f.read() # New line
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks I got it.then how do i make use of buttons which i created using pyQT??
If you're using PyQt5 this shoul work: openfile = PyQt5.QtWidgets.QFileDialog.getOpenFileName(self)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.