Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt - assign to a button the ability to choose a directory

Tags:

python

pyqt

I am having trouble searching for the method to assign to a Push Button the ability to choose a directory. I found this how to have a directory dialog in Pyqt, but I am still unsure about the method.

For example, I have a push button called new_directory and I have this code self.new_directory.clicked.connect(self.pick_new). What do I need to put into the function pick_new so that when new directory is clicked I can choose a new directory and have this stored in a variable?

Thanks!

like image 362
jim mako Avatar asked Oct 27 '25 11:10

jim mako


1 Answers

I think this might help you. With this you can get the directory.

def pick_new():
    dialog = QtGui.QFileDialog()
    folder_path = dialog.getExistingDirectory(None, "Select Folder")
    return folder_path
like image 102
Rajiv Sharma Avatar answered Oct 28 '25 23:10

Rajiv Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!