我复制了一个简单的PyQt5。QtWidgets.QFileDialog网络上的代码,但我发现
此代码在我的设备中不起作用,我不确定我的环境中是否有不兼容的地方。在
我的python版本:Python3.4。32位
PyQt版本:PyQt5.5 32位
错误是:
“pythonw.exe运行时停止工作QFileDialog.getExistingDirectory“
请看下面的屏幕截图和代码
from PyQt5.QtWidgets import QMainWindow, QApplication, QDialog,QFileDialog
from os.path import expanduser
import sys
import design
class ExampleApp(QMainWindow, design.Ui_MainWindow):
def __init__(self, parent=None):
super(ExampleApp, self).__init__()
self.setupUi(self)
self.btnBrowse.clicked.connect(self.browse_folder)
def browse_folder(self):
self.listWidget.clear()
directory = QFileDialog.getExistingDirectory(self,
"Pick a folder")
if directory:
for file_name in os.listdir(directory):
self.listWidget.addItem(file_name)
def main():
app = QApplication(sys.argv)
form = ExampleApp()
form.show()
app.exec_()
if __name__ == '__main__':
main()