美文网首页
python3 运行turtle

python3 运行turtle

作者: 寻找无名的特质 | 来源:发表于2022-04-14 05:57 被阅读0次

今天尝试在Ubuntu上使用turtle,运行环境是python3,遇到一些问题,将解决过程记录如下。首先是turtle包的安装出现问题,查了一下,发现setup.py是python2编写的,其中第40行代码需要修改,手工下载turtle.0.0.2的安装包,解压并修改后,使用pip3 install -e turtle-0.0.2 安装。编写并运行下面的代码:

#!/usr/bin/env python3

# 导入turtle包的所有内容:
from turtle import *

# 设置笔刷宽度:
width(4)

# 前进:
forward(200)
# 右转90度:
right(90)

# 笔刷颜色:
pencolor('red')
forward(100)
right(90)

pencolor('green')
forward(200)
right(90)

pencolor('blue')
forward(100)
right(90)

# 调用done()使得窗口等待被关闭,否则将立刻关闭窗口:
done()

出现问题:
ModuleNotFoundError: No module named 'tkinter'

发现是基础包没有安装,使用下面命令安装:
sudo apt install python3-tk
安装完成后,可以运行了。

相关文章

  • 自动画圆圈代码

    在python3的idle中键入以下代码并运行 import turtle t = turtle.Pen() ...

  • python3 运行turtle

    今天尝试在Ubuntu上使用turtle,运行环境是python3,遇到一些问题,将解决过程记录如下。首先是tur...

  • 递归可视化:使用turtle库画分形树(二叉树)

    turtle是Python3重要的内置标准库,它能够进行基本的图形绘制,以LOGO语言为基础。turtle库绘制图...

  • matlab和虚拟机下ros通信

    打开虚拟机---打开一个终端---输入:roscore; 运行turtle的来作为实例:rosrun turtle...

  • python

    Mac环境 安装/运行python3 终端运行 brew install python3 即可安装 终端运行pyt...

  • turtle库安装

    安装turtle 1.Python2安装命令: 2.Python3安装命令: python3安装提示错误 分析安装...

  • Mac 安装python3

    通过homebrew安装python,运行brew search python3搜索到python3安装包后,运行...

  • python3安装turtle

    问题1 pip3 install turtle 安装报错 解决 下载turtle源码:https://files....

  • Turtle制作时钟表

    利用Python Turtle库可以制作时钟表盘,动态运行 结果如下: 代码如下:

  • turtle 海龟绘图

    导入turtle包 import turtle # 导入turtle库 import turtle # 设置窗体(...

网友评论

      本文标题:python3 运行turtle

      本文链接:https://www.haomeiwen.com/subject/hqhksrtx.html