Reputation: 35
I am having a problem where I cannot link my open Button to the "open" command, help please!
Error= fileName = tkFileDialog.askopenfilename()
NameError: global name 'tkFileDialog' is not defined
What I have:
from Tkinter import *
from tkFileDialog import askopenfilename
frm = Frame(parent)
frm.pack(fill=X)
Button(frm, text=' Browse ', command=self.getFileName).pack(side=LEFT)
def getFileName(self):
fileName = tkFileDialog.askopenfilename()
iconEntry.insert(0, fileName)
SimpleEditor().mainloop()
Upvotes: 1
Views: 10251
Reputation: 1
instead of usingfrom tkFileDialog import askopenfilename
useimport Tkinter.Filedialog as tkFiledialog
Upvotes: 0
Reputation: 5405
yeah. Since you are already doing "tkFileDialog.askopenfilename()", you don't need to do this "from tkFileDialog import askopenfilename"
Simply, import tkFileDialog will do.
Upvotes: 0
Reputation: 310287
rather than
from tkFileDialog import askopenfilename
you probably just want
import tkFileDialog
Upvotes: 3