**这是编程课程的一部分,我们被要求使用的模块通常不会在其他情况下使用。我会尽我所能解释我的代码(虽然它是不言自明的)
编辑:如果你很好奇,我必须使用Myro,我用来获取鼠标点击坐标的代码是:mouseX, mouseY = win.getMouse() # "win" refers to a Window object
我正在创建“按钮”,当单击时执行某种形式的操作。我使用了三种不同的形状:矩形、圆形和三角形。
对于矩形:
# The numbers used in this example are the coordinates on an XY plane
# mouseX refers to the X coord of a recent mouse click; mouseY on the Y axis
if mouseX >= 70 and mouseX <= 120:
if mouseY >= 10 and mouseY <= 35:
print("rectangle button clicked")
对于圈子,我从这个问题中得到了帮助,最后得到了这个代码:
# mouseX and mouseY, same as rectangle example
if sqrt((mouseX-660)**2 + (mouseY-270)**2) <= 30:
print("circle button clicked")
我尝试使用的最后一个形状是三角形。我不确定我将如何确保mouseX
并mouseY
在形状的坐标范围内。我的数学相当糟糕,但我假设有一些公式可以使用(例如圆圈示例)。非常感谢。