File Dialog Window 05-07-2016, 03:06 PM
#1
You know that file dialog window that some applications open? Yes, that one that's used to browse through files and choose one... Well, here's how you do it in Python.
Python 2:
Python 3:
Just a quick thing I thought I'd share.
Python 2:
Code:
import Tkinter
import tkFileDialog
# hide the parent window
root = Tkinter.Tk()
root.withdraw()
filename = tkFileDialog.askopenfilename()Spoiler:
There are also other tkFileDialog methods that can do things like directly open a file or choose a directory.
![[Image: KiVWDh4.png]](https://cdn.pbrd.co/images/KiVWDh4.png)
http://tkinter.unpythonic.net/wiki/tkFileDialog
![[Image: KiVWDh4.png]](https://cdn.pbrd.co/images/KiVWDh4.png)
http://tkinter.unpythonic.net/wiki/tkFileDialog
Python 3:
Code:
from tkinter import filedialog
import tkinter
# hide the parent window
root = tkinter.Tk()
root.withdraw()
filename = filedialog.askopenfilename()Spoiler:
The methods used for tkinter.filedialog are probably the same as used by Python 2's tkFileDialog.
![[Image: KiVWDh4.png]](https://cdn.pbrd.co/images/KiVWDh4.png)
http://tkinter.unpythonic.net/wiki/tkFileDialog
![[Image: KiVWDh4.png]](https://cdn.pbrd.co/images/KiVWDh4.png)
http://tkinter.unpythonic.net/wiki/tkFileDialog
Just a quick thing I thought I'd share.







![[+]](https://sinister.li/images/modern/collapse_collapsed.png)