简体   繁体   中英

Tkinter NameError only when running script from shell

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM