PythonTkintersimpledialog.askstring无法从命令提示符工作

2024-10-03 02:43:22 发布

您现在位置:Python中文网/ 问答频道 /正文

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

所以我用python3.2.2的IDLE用python的tkinter编写了一个gui。当我在交互模式下从空闲状态运行程序时,一切正常,但是当我通过双击它或从命令提示符运行它时,它会产生一个错误,并且不会启动程序。我知道问题出在这条线上:

path_da=self.simdia.askstring("Path to start","Paths must be relative!")

我从金特进口了所有的东西。 path_da被假定为askstring对话框中的字符串。 我在类中将simdia设置为simpledialog作为公共变量。 我只是不明白为什么在空闲状态下使用F5运行它,而不是从命令提示符下运行它


Tags: pathin程序状态script空闲dabut
1条回答
网友
1楼 · 发布于 2024-10-03 02:43:22

我将此标记为dupe,因为使用simpledialog.askstring而不从tkinter模块导入simpledialog时收到的错误与使用simpledialog时相同。如果它不被认为是重复的,答案如下:

引用Roger's answer对类似的问题:

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*

尝试将此添加到代码中:

^{pr2}$

相关问题 更多 >