chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


File Dialog Window filter_list
Author
Message
File Dialog Window #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:
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]
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]
http://tkinter.unpythonic.net/wiki/tkFileDialog

Just a quick thing I thought I'd share.

Reply






Users browsing this thread: 1 Guest(s)