mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
added file explorer dialog box script
This commit is contained in:
parent
9a1a19707d
commit
d9d9ec04dc
20
File-Explorer-Dialog-Box/README.md
Normal file
20
File-Explorer-Dialog-Box/README.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# File Explorer Dialog Box in Python
|
||||
|
||||
## 1. Using tkinter
|
||||
|
||||
Just run
|
||||
|
||||
```
|
||||
$ python select_file_tk.py
|
||||
```
|
||||
|
||||
## 2. Using PyQt
|
||||
|
||||
Install [PyQt5](https://pypi.org/project/PyQt5/)
|
||||
|
||||
|
||||
Just run
|
||||
|
||||
```
|
||||
$ python select_file_pyqt.py
|
||||
```
|
18
File-Explorer-Dialog-Box/select_file_pyqt.py
Normal file
18
File-Explorer-Dialog-Box/select_file_pyqt.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from PyQt5.QtWidgets import QFileDialog, QApplication
|
||||
from PyQt5 import QtWidgets
|
||||
|
||||
|
||||
def select_files(directory_location=None):
|
||||
qtapp = QApplication([directory_location])
|
||||
qtwgt = QtWidgets.QWidget()
|
||||
filenames, _ = QFileDialog.getOpenFileNames(qtwgt)
|
||||
return filenames
|
||||
|
||||
|
||||
def main():
|
||||
filenames = select_files()
|
||||
print("You selected:\n", "\n".join(filename for filename in filenames))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
8
File-Explorer-Dialog-Box/select_file_tk.py
Normal file
8
File-Explorer-Dialog-Box/select_file_tk.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
|
||||
file_path = filedialog.askopenfilename()
|
||||
print(file_path)
|
Loading…
Reference in New Issue
Block a user