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?

Gokul Krishna
  • 105
  • 2
  • 5

1 Answers1

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
Lachlan
  • 1,245
  • 5
  • 18
  • 34