added file explorer dialog box script

This commit is contained in:
nikhilkumarsingh 2018-10-03 11:45:59 +05:30
parent 9a1a19707d
commit d9d9ec04dc
3 changed files with 46 additions and 0 deletions

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

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)