Tkinter tkFileDialog doesn't exist
Question:
I’m trying to show a open file dialog using Tkinter in Python. Every example I find seems very easy to use, but they all start with the line:
import tkFileDialog
This line throws an error for me, saying
No module named 'tkFileDialog'
It seems my Python doesn’t have tkFileDialog
. So I tried searching for it, but it seems that you don’t “download” Tkinter, it just comes with Python. Why is my Tkinter missing tkFileDialog? Is there somewhere I can acquire it so that I can use it?
Another thing I thought is that maybe it has changed names since the examples I’ve read were written. Is there a different way to import tkFileDialog
in Python 3?
I’m running Windows 7 64-bit, Python version
3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)]
Any help would be greatly appreciated!
Answers:
That code would have worked fine in Python 2.x, but it is no longer valid. In Python 3.x, tkFileDialog
was renamed to filedialog
and placed inside the Tkinter package. Nowadays, you import it like so:
import tkinter.filedialog
# or
from tkinter import filedialog
I’m trying to show a open file dialog using Tkinter in Python. Every example I find seems very easy to use, but they all start with the line:
import tkFileDialog
This line throws an error for me, saying
No module named 'tkFileDialog'
It seems my Python doesn’t have tkFileDialog
. So I tried searching for it, but it seems that you don’t “download” Tkinter, it just comes with Python. Why is my Tkinter missing tkFileDialog? Is there somewhere I can acquire it so that I can use it?
Another thing I thought is that maybe it has changed names since the examples I’ve read were written. Is there a different way to import tkFileDialog
in Python 3?
I’m running Windows 7 64-bit, Python version
3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)]
Any help would be greatly appreciated!
That code would have worked fine in Python 2.x, but it is no longer valid. In Python 3.x, tkFileDialog
was renamed to filedialog
and placed inside the Tkinter package. Nowadays, you import it like so:
import tkinter.filedialog
# or
from tkinter import filedialog