0

I my trying to retrieve a string variable for the selected path.

class ExampleApp(QtGui.QMainWindow, design.Ui_MainWindow):

def __init__(self):

    super(self.__class__, self).__init__()
    self.setupUi(self)  

    A = self.in_browse_button.clicked.connect(self.browser)

def browser(self):
    global directory
    directory = str(QFileDialog.getExistingDirectory())
    self.input_edit.setText(directory)
    return directory

The dialog open when I press the button but when I try to use A variable it's value is None. Any idea?

1 Answer 1

1

This code

A = self.in_browse_button.clicked.connect(self.browser)

does not assign the result of self.browser but result of clicked signal to the variable A. According to the documentation, signal clicked does not return anything. Therefore, since you are in a class, I recommend defining an attribute for the class and store result of QFileDialog in there.

class ExampleApp(QtGui.QMainWindow, design.Ui_MainWindow):
    def __init__(self):
        super(self.__class__, self).__init__()
        self.setupUi(self)
        self.directory = None
        self.in_browse_button.clicked.connect(self.browser)

    def browser(self):
        self.directory = str(QFileDialog.getExistingDirectory())
        self.input_edit.setText(directory)
Sign up to request clarification or add additional context in comments.

Comments

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.