Непонятно, что вы спрашиваете - что вы подразумеваете под «открыть каталог»? Вы хотите получить ссылку на путь к каталогу?
Предполагая, что ваша кнопка находится внутри другого класса:
button1 = QtGui.QPushButton("This is button1", self)
# set button to call somefunction() when clicked
buton1.clicked.connect(self.somefunction)
def somefunction(self):
# this is called when button1 is clicked
# put directory specific tasks here
# examples:
ddir = QtGui.QFileDialog.getExistingDirectory(self, "Get Dir PAth")
# ddir is a QString containing the path to the directory you selected
print ddir # this will output something like 'C://path/you/selected'
# lets get a list of files from the directory:
files = [name for name in os.listdir(str(ddir))]
# txt files only:
files = [name for name in os.listdir(str(ddir)) if name.endswith('.txt')]
# jpg files only:
files = [name for name in os.listdir(str(ddir)) if name.endswith('.jpg')]
# now do something with your directory or list of files ...
Там нет такого понятия; Вы можете '' os.listdir() '' и отображать содержимое каталога. –
Подключите сигнал 'clicked()' к слоту (т. Е. К функции, методу или любому другому вызываемому на Python объекту). В слоте поместите код, который показывает каталог (например, [QFileDialog.getExistingDirectory()] (http://doc.qt.io/qt-4.8/qfiledialog.html#getExistingDirectory)). – ekhumoro