1

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()   

3 Answers 3

3

rather than

from tkFileDialog import askopenfilename

you probably just want

import tkFileDialog
Sign up to request clarification or add additional context in comments.

Comments

0

yeah. Since you are already doing "tkFileDialog.askopenfilename()", you don't need to do this "from tkFileDialog import askopenfilename"

Simply, import tkFileDialog will do.

Comments

0

instead of usingfrom tkFileDialog import askopenfilename

useimport Tkinter.Filedialog as tkFiledialog

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.