im doing a tut for Tkinter and in it they do this:

tkFileDialog.askopenfilename()

but when i run it i get this error:
Traceback (most recent call last):
File "C:\Documents and Settings\tom\Desktop\Programing\Python\c++ + python\main.py", line 67, in <module>
if __name__ == "__main__": main()
File "C:\Documents and Settings\tom\Desktop\Programing\Python\c++ + python\main.py", line 64, in main
app = App(root)
File "C:\Documents and Settings\tom\Desktop\Programing\Python\c++ + python\main.py", line 13, in __init__
File "C:\Documents and Settings\tom\Desktop\Programing\Python\c++ + python\main.py", line 42, in openFile
NameError: global name 'tkFileDialog' is not defined

any ideas?

4
Contributors
5
Replies
7
Views
8 Years
Discussion Span
Last Post by tomtetlaw

Can I see the rest of your code?
I don't use Tk (I find wxPython to be much better), but what happens if you replace that line with

tk.FileDialog.askopenfilename()

Of course, that would assume tk has a class named FileDialog and that you use Tkinter like

import tk

Hope that helped with something.

Can I see the rest of your code?
I don't use Tk (I find wxPython to be much better), but what happens if you replace that line with

tk.FileDialog.askopenfilename()

Of course, that would assume tk has a class named FileDialog and that you use Tkinter like

import tk

Hope that helped with something.

Yeah Shadwickman is right. Anything with TK you have to import it first before it will work. Good Luck

Yeah Shadwickman is right. Anything with TK you have to import it first before it will work. Good Luck

Or any other modules (or parts of modules) you want to use, like os, sys, time, threading, wx, etc. :P

Here would be a typical example using the tkFileDialog ...

# using the file dialog without a tk window

import Tkinter as tk
import tkFileDialog

root = tk.Tk()
# show file dialog without Tkinter window
root.withdraw()

# defaults to current directory and all file types
print(filename)