Turtle是python内置的图形化模块,可以用来绘制线条、圆、文本等图形。
首先要在ubuntu终端中安装Tkinter,执行命令sudo apt-get install python-tk 即可,否则会报错。安装完之后就可以在终端里执行turtle绘制或则在eclipse环境中执行。(附:由于ubuntu12.04自带的python版本是2.7.3,所以此时利用终端安装的python-tk是与该python版本对应的,所以在python2.7.3的解释器下没有问题,而在我另装的python3.2.3的解释器下会报ImportError: No module named _tkinter,此时我的做法是更换为2.7的解释器,不过我想应该可以直接下载python3.2.3对应的python-tk版本安装)
根据书上写了个小程序
#coding=utf-8
import time
import turtle #import turtle module
turtle.showturtle() #show turtle graph
turtle.write("welcome to python测试中文")
turtle.forward(100) #箭头向右延长100
time.sleep(3) #休眠3秒
turtle.right(90) #方向顺时针转90度
turtle.color("red") #颜色设为红色
turtle.forward(50) #长度50
time.sleep(3)
turtle.right(90) #方向顺时针转90度
turtle.color("green") #颜色设为绿色
turtle.forward(100)