![]() |
|
File Dialog Window - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Python (https://sinister.li/Forum-Python) +--- Thread: File Dialog Window (/Thread-File-Dialog-Window) |
File Dialog Window - m0dem - 05-07-2016 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: 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. ![]() 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. ![]() http://tkinter.unpythonic.net/wiki/tkFileDialog Just a quick thing I thought I'd share. |