mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2025-01-31 05:33:41 +00:00
Merge pull request #11 from nikhilkumarsingh/master
added file explorer dialog box script
This commit is contained in:
commit
3ee6a73eaf
23
File-Explorer-Dialog-Box/README.md
Normal file
23
File-Explorer-Dialog-Box/README.md
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# File Explorer Dialog Box in Python
|
||||||
|
|
||||||
|
Open file explorer dialog box UI to select files using Python.
|
||||||
|
|
||||||
|
|
||||||
|
## 1. Using tkinter
|
||||||
|
|
||||||
|
Example using tkinter:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ python select_file_tk.py
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. Using PyQt
|
||||||
|
|
||||||
|
Install [PyQt5](https://pypi.org/project/PyQt5/)
|
||||||
|
|
||||||
|
|
||||||
|
Example using PyQt5:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ 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