Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.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
Python tkinter:在透明形状中单击don';t寄存器_Python_Tkinter - Fatal编程技术网

Python tkinter:在透明形状中单击don';t寄存器

Python tkinter:在透明形状中单击don';t寄存器,python,tkinter,Python,Tkinter,相当简单的一个,这个。例如: a = canvas.create_circle(0,0,50,50,outline='red',width=3,fill='') b = canvas.create_circle(0,0,50,50,outline='red',width=3,fill='red') b将响应圆圈中任何位置的点击事件,而a仅响应对轮廓的点击 有没有比简单地使用几乎透明的颜色来填充更好的方法呢?答案多少取决于你如何定义“更好”。确实,如果对象没有填充颜色,则单击不会注册。一个选项是

相当简单的一个,这个。例如:

a = canvas.create_circle(0,0,50,50,outline='red',width=3,fill='')
b = canvas.create_circle(0,0,50,50,outline='red',width=3,fill='red')
b
将响应圆圈中任何位置的点击事件,而
a
仅响应对轮廓的点击


有没有比简单地使用几乎透明的颜色来填充更好的方法呢?

答案多少取决于你如何定义“更好”。确实,如果对象没有填充颜色,则单击不会注册。一个选项是将单击事件放在画布本身上,然后使用画布
find_closest
find_overlapping
方法查找距离光标最近的对象

您可以使用多边形而不是椭圆形:

a = canvas.create_polygon(100,100,50,150,100,200,150,150, outline='red', fill='', smooth=1)
编辑:

多边形对鼠标单击很敏感,即使它没有填充颜色(或轮廓)


请参阅canvas文档:

有点晚了,但这里是问题的解决方案。在您的例子中,您可以注意到,如果单击无填充对象本身的轮廓,将触发单击事件。 (不知道为什么,但它的行为是这样的)

现在,如果您同时删除轮廓和填充,即

a=canvas.create_圈(0,0,50,50,outline='',fill='')
不可见(无填充,无轮廓)将触发单击事件,就像另一个圆圈“b”一样

因此,您可以创建一个不可见的圆(没有填充,没有轮廓),将其绑定到触发器事件。 然后用所需的轮廓参数在其正上方创建另一个圆(相同的坐标)


这将产生一个没有填充的单轮廓圆的幻觉,并且仍然会触发单击事件。

这仍然不能解决问题problem@jamylak:为什么它不能解决问题?你是说在你的回调中找不到最近的对象吗?
find\u closest
不起作用,
find\u overlapping
不会返回没有填充的椭圆形。如果你把所有的东西都装好,很抱歉,但我不知道这是如何解决问题的。为什么需要使用多边形?