python 小海龟鼠标画图_Python+turtle交互式绘图:可以用鼠标拖动的小海龟

下面是我画海龟的过程:

(1)打开python:

2、调用turtle库,先设置一些基础设置,与一个画龟的函数

from turtle import Screen,Turtle,mainloop

class ColorTurtle(Turtle):

def __init__(self,x,y):

Turtle.__init__(self)

self.shape("turtle")

self.resizemode("usre")

self.shapesize(3,3,0)

self.pensize(10)

self._color=[0,0,0]

self.x=x

self._color[x]=y

self.color(self._color)

self.speed(0)

self.left(90)

self.up()

self.goto(x,0)

self.down()

self.sety(1)

self.up()

self.sety(y)

self.pencolor("black")

self.ondrag(self.shift)

3、设计shift函数

defshift(self,x,y):

self.sety(max(o,min(y,1)))

self._color[self.x]=self.ycor()

self.fillcolor(self._color

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值