小编Mit*_*ola的帖子

单击圆圈内的任何位置时,使用Python验证鼠标位置是否在圆圈内.

我正在研究Python中的一个项目,即确定一个人的多任务效率.该项目的一部分是让用户使用鼠标在屏幕上响应事件.我决定让用户点击一个球.但是我的代码验证鼠标光标实际上是在圆圈的范围内.

有关方法的代码如下.圆的半径是10.

    #boolean method to determine if the cursor is within the position of the circle
    @classmethod
    def is_valid_mouse_click_position(cls, the_ball, mouse_position):
        return (mouse_position) == ((range((the_ball.x - 10),(the_ball.x + 10)), 
                                 range((the_ball.y + 10), (the_ball.y - 10))))

    #method called when a pygame.event.MOUSEBUTTONDOWN is detected.
    def handle_mouse_click(self):
    print (Ball.is_valid_mouse_click_position(self.the_ball,pygame.mouse.get_pos))
Run Code Online (Sandbox Code Playgroud)

无论我在圈内单击,布尔值仍然返回False.

python pygame boolean mouseevent

3
推荐指数
1
解决办法
2144
查看次数

标签 统计

boolean ×1

mouseevent ×1

pygame ×1

python ×1