我怎样才能让特金特在空闲时间外工作?

2024-03-29 15:17:00 发布

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

当我在IDLE中运行python脚本时,tkinter可以正常工作,但是当我尝试直接通过python启动程序或命令行运行脚本时,我得到以下消息:

Traceback (most recent call last):
  File "/Users/maclaren/Documents/hellotkinter.py", line 1, in <module>
    import tkinter
ImportError: No module named tkinter

我在mac上编码,请帮忙。如何让我的程序在IDE之外运行?你知道吗


Tags: 命令行程序脚本消息mosttkintercallusers
1条回答
网友
1楼 · 发布于 2024-03-29 15:17:00

您可能正在使用空闲的python3。在命令行中,python2是默认值。您应该将导入更改为

import tkinter

import Tkinter

或者可以在命令行中使用python3。这是最好的选择,因为有些Tk小部件只在python3中可用。而不是这样:

cd /Users/maclaren/Documents
python hellotkinter.py

尝试:

cd /Users/maclaren/Documents
python3 hellotkinter.py

或者

cd /Users/maclaren/Documents
py hellotkinter.py

相关问题 更多 >