Question

I am using PyQt4 to create a single window to prompt the user to input text (like the name of the report) and to select files to generate a report.

I'd like to keep everything in that window. It's a little bit of a dumb window... there's buttons on the left and fields on the right. For the text inputs, I have a button to accept the QLineEdit that is on the right. I want there to also be some sort of feedback for the ones where the user is specifying a file, so they know that they've entered all of the info that the program needs (or they can double check that they chose the right file).

I figured the easiest way to do this is to show the path of the chosen files by adding a QLabel widget to the grid layout. I'm not sure what I'm doing wrong...I set it initially to '', and then I tell it to set the text to the file path in the function that the button is connected to.

    self.Logo_button = QtGui.QPushButton(names[1], self)
    self.LogoLabel = QLabel()
    self.LogoLabel.setText = ''
    self.Logo_button.clicked.connect(self.logo_pic)
    grid.addWidget(self.Logo_button, 1, 0)
    grid.addWidget(self.LogoLabel, 1,1)

def logo_pic(self):
    self.Logo_picture = unicode(QtGui.QFileDialog.getOpenFileName())
    self.LogoLabel.setText = self.Logo_picture
Was it helpful?

Solution

You are assigning a string to self.LogoLabel.setText as if it was a data attribute. But it's not - it's a method. So instead, you should do:

    self.LogoLabel.setText(self.Logo_picture)

There's no need to initialize the text of the label: it's already set to an empty string by default.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top