From d9d9ec04dcc97dff6e9892d00f45deb55e2b2b13 Mon Sep 17 00:00:00 2001 From: nikhilkumarsingh Date: Wed, 3 Oct 2018 11:45:59 +0530 Subject: [PATCH 1/2] added file explorer dialog box script --- File-Explorer-Dialog-Box/README.md | 20 ++++++++++++++++++++ File-Explorer-Dialog-Box/select_file_pyqt.py | 18 ++++++++++++++++++ File-Explorer-Dialog-Box/select_file_tk.py | 8 ++++++++ 3 files changed, 46 insertions(+) create mode 100644 File-Explorer-Dialog-Box/README.md create mode 100644 File-Explorer-Dialog-Box/select_file_pyqt.py create mode 100644 File-Explorer-Dialog-Box/select_file_tk.py diff --git a/File-Explorer-Dialog-Box/README.md b/File-Explorer-Dialog-Box/README.md new file mode 100644 index 0000000..ad467b6 --- /dev/null +++ b/File-Explorer-Dialog-Box/README.md @@ -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 +``` \ No newline at end of file diff --git a/File-Explorer-Dialog-Box/select_file_pyqt.py b/File-Explorer-Dialog-Box/select_file_pyqt.py new file mode 100644 index 0000000..fbb5bcf --- /dev/null +++ b/File-Explorer-Dialog-Box/select_file_pyqt.py @@ -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() diff --git a/File-Explorer-Dialog-Box/select_file_tk.py b/File-Explorer-Dialog-Box/select_file_tk.py new file mode 100644 index 0000000..0b4c0f6 --- /dev/null +++ b/File-Explorer-Dialog-Box/select_file_tk.py @@ -0,0 +1,8 @@ +import tkinter as tk +from tkinter import filedialog + +root = tk.Tk() +root.withdraw() + +file_path = filedialog.askopenfilename() +print(file_path) From 6c44152a4278a6a93a27769c188684860a8affff Mon Sep 17 00:00:00 2001 From: Nikhil Kumar Singh Date: Wed, 3 Oct 2018 14:12:26 +0530 Subject: [PATCH 2/2] Update README.md --- File-Explorer-Dialog-Box/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/File-Explorer-Dialog-Box/README.md b/File-Explorer-Dialog-Box/README.md index ad467b6..24cfe88 100644 --- a/File-Explorer-Dialog-Box/README.md +++ b/File-Explorer-Dialog-Box/README.md @@ -1,8 +1,11 @@ # File Explorer Dialog Box in Python +Open file explorer dialog box UI to select files using Python. + + ## 1. Using tkinter -Just run +Example using tkinter: ``` $ python select_file_tk.py @@ -13,8 +16,8 @@ $ python select_file_tk.py Install [PyQt5](https://pypi.org/project/PyQt5/) -Just run +Example using PyQt5: ``` $ python select_file_pyqt.py -``` \ No newline at end of file +```