This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: turtle with compound shape doesn't get clicks
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: gregorlingl, ingrid, jesstess, pythonick, willingc
Priority: normal Keywords: needs review, patch

Created on 2012-11-07 14:46 by pythonick, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
issue_16428.patch ingrid, 2014-06-03 04:39 review
issue_16428.patch ingrid, 2014-06-12 00:47 review
Messages (5)
msg175106 - (view) Author: (pythonick) Date: 2012-11-07 14:46
In the standard turtle module, when a turtle has a custom shape of type "compound", it doesn't to respond to click events. No problem with polygon shapes.

Observed on Windows XP, python 3.2.3, turtle version 1.1b, and on Linux, python 2.7. 

Test code:

##################################################
import turtle
square = ((0,0),(0,20),(20,20),(20,0))
turtle.addshape("sq1", square) # sq1 = polygon shape
s = turtle.Shape("compound")
s.addcomponent(square, "red")
turtle.addshape("sq2", s) # sq2 = compound shape
t1 = turtle.Turtle(shape="sq1")
t2 = turtle.Turtle(shape="sq2")
t2.fd(20)
def click(x,y): print("click at",x,y)
t1.onclick(click)
t2.onclick(click)
turtle.mainloop()
##################################################

When you click on the black square (i.e. t1), the message "click at..." is printed. When you click on the red square (i.e. t2), nothing happens.
msg218970 - (view) Author: (ingrid) * Date: 2014-05-23 13:26
I tried the same script in Python 2.7 and Python 3.4.1 on OSX and had the same results.
msg219658 - (view) Author: (ingrid) * Date: 2014-06-03 04:39
Looks like the issue is that when you are registering mouse events through turtle, it uses Shape._item. For polygon shapes, that's the actual shape item, but for compound shapes, it is an array of shape items. I have attached a patch that makes it so when there is a compound shape, it will iterate over the _item array and add the listener to each individual shape.
msg220326 - (view) Author: (ingrid) * Date: 2014-06-12 00:47
I updated the patch to use the gui check in Lib/test/support, and I renamed the test file to be test_turtle_guionly.
msg319747 - (view) Author: Carol Willing (willingc) * (Python committer) Date: 2018-06-16 15:12
This issue is "new contributor"-friendly.

The next steps would be to apply the patch to a recent version of Python 3, check if tests run cleanly, and if the patch resolves the issue.

I'm sorry ingrid that the patch review languished on the issue tracker.
History
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60632
2018-06-16 15:12:16willingcsetnosy: + willingc

messages: + msg319747
versions: + Python 3.6, - Python 2.7, Python 3.2
2014-08-03 19:02:07jesstesssetkeywords: + needs review
stage: patch review
2014-06-12 00:47:38ingridsetfiles: + issue_16428.patch

messages: + msg220326
2014-06-03 04:39:14ingridsetfiles: + issue_16428.patch
keywords: + patch
messages: + msg219658
2014-05-24 05:33:33Jessica.McKellarsetnosy: + jesstess
2014-05-23 19:16:46ned.deilysetnosy: + gregorlingl
2014-05-23 13:26:04ingridsetnosy: + ingrid
messages: + msg218970
2012-11-07 14:46:49pythonickcreate