0

I am having trouble using tkFileDialog.askopenfile() in Python 2.7.11

The following code produces the error.

import Tkinter

print Tkinter.TkVersion
Tkinter.tkFileDialog.askopenfile(filetypes=[('csvfiles','.csv')])

The Python Shell output is:

8.5

Traceback (most recent call last):
  File "C:/Users/User1/Desktop/tmp.py", line 4, in <module>
    Tkinter.tkFileDialog.askopenfile(filetypes=[('csvfiles','.csv')])
AttributeError: 'module' object has no attribute 'tkFileDialog'
>>> 

If I'm making a terribly stupid mistake then I apologize but I can't seem to find it. Otherwise, are there other dialog boxes I can use in Tkinter to have a user select a file? Thanks.

martineau
  • 119,623
  • 25
  • 170
  • 301
Tyler
  • 27
  • 1
  • 5

1 Answers1

2

for python 2.7 its a separate module:

from tkFileDialog import askopenfilename

In python 3 its included in tkinter :

from tkinter import filedialog as fd
shivsn
  • 7,680
  • 1
  • 26
  • 33