Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script works in IDLE, but .py-file doesn't work

I have a tkinter script, which runs just fine in IDLE. However, when I double click the .py-file from Windows Explorer, the console window flashes half a second and then it exits.

I was able to screenprint the console window. It says:

...etc.etc...
NameError: global name 'simpledialog' is not defined

simpledialog is a module in tkinter which I use in my script. As I do from tkinter import *, there is no need to explicitly write tkinter.simpledialog.

It works in IDLE, why not as .py?

like image 621
wjakobw Avatar asked Nov 29 '11 23:11

wjakobw


1 Answers

IDLE uses Tkinter as its graphical environment. It is possible that your code is relying on a side effect of an import by IDLE itself. This is especially true if you use IDLE without a subprocess.

The simpledialog module does not import when using from tkinter import *. Try adding this to your code:

import tkinter.simpledialog as simpledialog
like image 161
Roger Avatar answered Sep 23 '22 03:09

Roger