Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graphics 如何检测用户是否在python图形窗口中单击圆圈内部_Graphics_Python 3.x - Fatal编程技术网

Graphics 如何检测用户是否在python图形窗口中单击圆圈内部

Graphics 如何检测用户是否在python图形窗口中单击圆圈内部,graphics,python-3.x,Graphics,Python 3.x,在我的程序中,我在图形窗口中画了三个圆圈,我需要根据用户单击的圆圈做出不同的响应 cup1 = Circle(Point(35,100),25) cup1.draw(win) cup2 = cup1.clone() cup2.move(65,0) cup2.draw(win) cup3 = cup1.clone() cup3.move(130,0) cup3.draw(win) 所以我需要这样的东西: userchoice

在我的程序中,我在图形窗口中画了三个圆圈,我需要根据用户单击的圆圈做出不同的响应

    cup1 = Circle(Point(35,100),25)
    cup1.draw(win)
    cup2 = cup1.clone()
    cup2.move(65,0)
    cup2.draw(win)
    cup3 = cup1.clone()
    cup3.move(130,0)
    cup3.draw(win)
所以我需要这样的东西:

    userchoice = win.getMouse()
    cup1choice = False
    cup2choice = False
    cup3choice = False
    if userchoice in cup1:
        cup1choice = True
    if userchoice in cup2:
        cup2choice = True
    if userchoice in cup3:
        cup3choice = True

但我意识到圆圈是不可编辑的,所以我正在寻找其他方法来确定用户是在杯子1、2还是3内单击。如果有人能帮上忙,我将非常感谢

您已经有了每个
圆的中心和半径
,您可以编写一个函数来确定给定的
是否在该范围内,如下所示:

from math import sqrt

def is_within(point, circle):
    distance = sqrt(((point.x - circle.x) ** 2) + 
                    ((point.y - circle.y) ** 2))
    return distance < circle.radius
从数学导入sqrt
def在(点、圆)内:
距离=平方米((点x-圆x)**2)+
((点y-圆y)**2))
返回距离<圆半径
请注意,必须根据正在使用的图形库调整属性名称