Click and show text only recognize last element of a list

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2022.2.4
Standard Standalone? (y/n) If not then what?: Yes
What are you trying to achieve?:
I have three pictures (cat, dog, pig) and want participant to click on any of the picture and a text of the object name will show up.

What did you try to make it work?:
Step 1: I uploaded three images and named them “cat”, “dog”, “pig”.
Step 2: added mouse component.
Step 3: created code component.
Begin routine:

clickables = ['cat','dog','pig']

Each Frame:

for clickable in clickables:
    if sum(mouse.getPressed()) == 0:
        object_name = ""
    if mouse.isPressedIn(clickable):
        object_name = clickable.name
        display.setPos(mouse.getPos() + 0.1)

Step 4:
created a text named “display”, which was also used in code to set its position.
The text Start condition is $mouse.isPressedIn(clickable)
Text is set to $object_name, which is defined in code.

What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.

Unexpected behavior: Only when the last element in clickables list is clicked, which is “pig” in this case, the text will show. Then “cat” or “dog” will show when they are clicked after “pig”.
But if cat or dog is clicked first, the text won’t show. The text shows only when the last element of the clickable list is clicked.

To debug, I changed the display’s Text from a variable “$object_name” to a string. The same odd behavior occurred. Therefore, I conclude the display’s Start condition " $mouse.isPressedIn(clickable)" only triggers when the last element of clickables list is clicked.

My question may narrow down to How to set the display (text) Start condition that no matter which image is clicked, the Text content will show.
clickshow.psyexp (16.7 KB)

I solved the problem by manually coding to draw the text instead of using the Start condition function of TextStim.

This is what I did to set the display(textStim) every time a clickable is clicked in the code.

for clickable in clickables:
    if sum(mouse.getPressed()) == 0:
        object_name = ""
    if mouse.isPressedIn(clickable):
        object_name = clickable.name
        display.setText(object_name)
        display.setSize(0.06)
        display.setForeColor("black")
        display.setPos(mouse.getPos() + 0.1)
        display.draw()

I took a detour to solve the problem, but I still couldn’t understand why the Start condition of a text stimli:
clickshow.psyexp (16.9 KB)
$mouse.isPressedIn(clickable) triggers only when the last element in the clickable list is clicked.