tkinter原生海龟拖动它画画示例_tkinter and RawTurtle example

"""
   tkinter原生海龟示例_tkinter and RawTurtle example
   本程序新建tkinter窗口,然后新建一块300X300的画布,再在画布上放一只海龟。
   定义了几个事件,可以拖动海龟画画。
"""

import turtle
import tkinter

root = tkinter.Tk()      # 新建一个窗口
cv = tkinter.Canvas(root,width=300,height=300)
cv.pack()
t = turtle.RawTurtle(cv) # 在画布上新建原生海龟
t.shape('turtle')
s = t.getscreen()        # 获取屏幕对象

def toggledown():
    """切换画笔状态"""
    if t.isdown():       # 如果是落笔则抬笔
        t.penup()
    else:
        t.pendown()

You must log in to read the rest of this article. Please log in or register as a user.