【发布时间】:2021-06-19 09:46:27
【问题描述】:
我想为海龟按钮创建一个类,并有一个作为海龟的字段 这是我写的代码:
class button:
def __init__(self,color,x,y):
self.turtle=turtle.Turtle()
self.turtle.penup()
self.turtle.shape("square")
self.turtle.color(color)
self.turtle.speed(0)
self.turtle.goto(x,y)
现在我想将onclick 用于按钮实例,那么我该怎么做呢?是这样的吗?
def click(self,x,y):
print ("hello world")
self.turtle.onclick()
顺便说一句,我的课程不太好,所以我只想要一些简单的东西。
【问题讨论】:
标签: python methods turtle-graphics python-turtle python-class