我对Python比较陌生,我正在使用tkinter画布。我目前使用
pos = canvas.coords(object)
speed = 5 #could be any number though
destpos = canvas.coords(destination)
xdist = destpos[2]-pos[2]
ydist = destpos[3]-pos[3]
#finds hypotenuse of an imaginary right triangle
fraction = speed/math.sqrt(xdist**2+ydist**2)
#puts the values into ratio so the object knows how far x and y they need to go
x = xdist * fraction
y = ydist * fraction
#canvas.move() function so the object moves
canvas.move(self.id, x, y)
但是,我想要一个简单的已经添加的方法,以给定的速度将一个对象移动到另一个目的地
在我正在开发的应用程序中,我需要多次使用此代码,与函数相比,我更喜欢使用更简单的方法
总之,我想要的是一个简单的方法来完成同样的任务,这是一个更容易理解的方法(这个方法有点麻烦,我一直搞不懂为什么)
目前没有回答
相关问题 更多 >
编程相关推荐