Python模块乌龟未正确导入

Python模块乌龟未正确导入

问题描述:

这是我第一次在 python 中使用乌龟模块,但我似乎无法导入它?这是我的代码:

This is my first time using the turtle module in python but I can't seem to import it? Here's my code:

import turtle

turtle.shape("turtle")
turtle.speed(1)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)

turtle.exitonclick()

我将其作为 $ python3 example.py 运行我得到

I run this as $ python3 example.py And I get

$ python3 example.py
Traceback (most recent call last):
File "example.py", line 1, in <module>
from turtle import *
File "/usr/lib/python3.7/turtle.py", line 107, in <module>
import tkinter as TK
ModuleNotFoundError: No module named 'tkinter'

如果我运行 Python2 python example.py

If I run Python2 python example.py

$ python example.py
Traceback (most recent call last):
File "example.py", line 1, in <module>
import turtle
File "/usr/lib/python2.7/lib-tk/turtle.py", line 107, in <module>
import Tkinter as TK
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in <module>
raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk package

It was

sudo apt install python3-tkinter