Better looking Tkinter File Dialogs for Python 2.7

Viewed 223

In my application, the user needs to browse for files. However, the askdirectory from tkFileDialog isn't really comfortable for using and browsing files since it's somewhat outdated. It looks like this:

enter image description here

What I want to achieve should look like the "default" windows browse dialog. Like this:

enter image description here

(Source https://www.pythontutorial.net/tkinter/tkinter-open-file-dialog/)

I am not sure (since I couldn't find proof) but I remember someone telling me that it looks like this because I am using Python 2.7 and not 3+. Is that true? Does an alternative exist?

1 Answers

You can try using askopenfilename(). It displays the standard Open File dialog box.

For example:

from tkinter import *
from tkinter import filedialog as fd

root = Tk()

root.title("Button to open files")
root.geometry("500x500")

def openfd(*args):
    askk = askopenfilename()

btn = Button(root, text="Click to open file", command=openfd)
btn.place(x=200, y=200)
root.mainloop()

You can read more about it at https://www.pythontutorial.net/tkinter/tkinter-open-file-dialog/.

Related