1

I've got a Tkinter Python program, a reduced version of which can be found below:

from tkinter import *
from tkinter.ttk import *

filedialog.askopenfilename()

When I run this script from IDLE, I do not get any errors.

However, when run from PowerShell, using python myscript.py I get

NameError: could not find name 'filedialog'

Windows 10 x64 on a mid-2012 MacBook Pro

2
  • My answer here: stackoverflow.com/questions/38806673/… described how to fix existing IDLE releases so they give the proper error. Commented Aug 6, 2016 at 20:48
  • @TerryJanReedy Thanks for fixing this! Much appreciated! Commented Aug 6, 2016 at 22:25

1 Answer 1

1

IDLE is probably importing it already, but in general since filedialog is a tkinter module it won't get imported with the bare:

from tkinter import *

Include an extra:

from tkinter import filedialog

and you should be good to go.

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

4 Comments

Why would the filedialog module not be included in the *?
Same as ttk (that you're already including separately), it's a module.
This is a known IDLE bug in idlelib.run. bugs.python.org/issue25507 The solution in all cases is to add the missing import, as Feneric said. I hope to do the needed refactoring before 3.6, but must add tests first to avoid introducing new, and perhaps worse, bugs.
The Q&A persuaded me to finish the issue. Starting with 3.5.3 and 3.6.0a4, "from tkinter import *; filedialog' will raise the appropriate NameError when run by IDLE.

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.