Merge pull request #11 from nikhilkumarsingh/master

added file explorer dialog box script
This commit is contained in:
Kaushlendra Pratap 2018-10-03 15:50:50 +05:30 committed by GitHub
commit 3ee6a73eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 0 deletions

View 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
```

View 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()

View 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)