Archie Godfrey
Archie Godfrey

Reputation: 143

How to make Tkinter File Dialog only display text files?

I want to control what files the Tkinter file dialog displays to the user. I only want the user to be able to see text files, instead of seeing all of the different types of files such as Word or PowerPoint documents.

Is there a way to specify the file type within the askopenfilename() function?

Edit

I tried to use this code

filename=tkFileDialog.askopenfilename(filetypes='txt')

Upvotes: 2

Views: 3944

Answers (1)

shad0w_wa1k3r
shad0w_wa1k3r

Reputation: 13362

You can pass a filetypes argument with (('text files', 'txt'),) value.

As per your try -

filename = tkFileDialog.askopenfilename(filetypes=(('text files', 'txt'),))

Upvotes: 5

Related Questions