利用python pyqt5做出选择多个文件并读取的界面
时间: 2023-12-19 12:06:03 浏览: 61
这是一个技术问题,我可以回答。您可以使用QFileDialog类来实现选择多个文件并读取的界面。下面是一个简单的示例代码:
```python
from PyQt5.QtWidgets import QApplication, QFileDialog, QWidget, QPushButton
import sys
class MyWidget(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Select multiple files')
self.setGeometry(100, 100, 300, 100)
button = QPushButton('Select files', self)
button.setGeometry(100, 30, 100, 30)
button.clicked.connect(self.select_files)
def select_files(self):
files, _ = QFileDialog.getOpenFileNames(self, 'Select files', '', 'Image Files (*.png *.jpg *.jpeg *.bmp);;All Files (*)')
print('Selected files:', files)
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = MyWidget()
widget.show()
sys.exit(app.exec_())
```
此代码将创建一个窗口,其中包含一个按钮。当用户单击按钮时,将显示文件对话框,使用户可以选择多个文件。选择的文件名将打印到控制台中。
相关推荐
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)