# Progress/Feedback bar using a polygon

**URL:** https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825
**Category:** Coding
**Created:** [February 10, 2025, 10:23am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825 "2025-02-10T10:23:34Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Clemence](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@Clemence](https://discourse.psychopy.org/u/Clemence)
#### Post date: [February 10, 2025, 10:23am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/1 "2025-02-10T10:23:34Z")

</div>

Hi,  
I am currently developing an experiment that involves a training procedure, and I need to show correct or incorrect answers using a gauge. The issue I’m encountering is that my progress bar does not fill up completely or decrease with each correct or incorrect response. Instead, it only has three positions. Ideally, after each trial, the bar should take the last position and either increase or decrease by a specific step, resulting in a new position.

I am using PsychoPy version: v2014.1.5.

Any advice or help would be greatly appreciated!

Here is my code in Begin routine :

progress = 0.5  
step = 0.05

# Barre de progression

bar = visual.Rect(win, width=progress, height=0.1, pos=[0, 0], fillColor=“gray”, lineColor=None)

# Texte explicatif

progress\_text = visual.TextStim(win, text=“Progression”, pos=(0, 0.15), color=“black”, height=0.04)

# Déterminer le feedback à afficher

if reinforcement == “positif”:  
feedback\_text.setText(“Correct !”)  
feedback\_text.setColor(‘green’)  
progress = min(progress + step, 1.0) # Limite à 100%  
bar.fillColor = “green”  
elif reinforcement == “négatif”:  
feedback\_text.setText(“Incorrect !”)  
feedback\_text.setColor(‘red’)  
progress = max(progress - step, 0.0) # Limite à 0%  
bar.fillColor = “red”

# Afficher les éléments (affichage automatique activé)

feedback\_text.setAutoDraw(True)  
progress\_text.setAutoDraw(True)  
bar.setAutoDraw(True)

# Durée du feedback

feedback\_duration = 2.0  
feedback\_clock = core.Clock()  
feedback\_clock.reset()

And here is my code in Each Frame :

# Mise à jour de la largeur de la barre à chaque frame

bar.width = progress \* 1.0 # La largeur de la barre est définie par la progression

# Dessiner les éléments à chaque frame (la barre, le texte, etc.)

progress\_text.draw() # Dessiner le texte explicatif  
bar.draw() # Dessiner la barre de progression

# Fin du feedback après le délai spécifié

if feedback\_clock.getTime() \>= feedback\_duration:  
feedback\_text.setAutoDraw(False)  
progress\_text.setAutoDraw(False)  
bar.setAutoDraw(False)  
continueRoutine = False # Arrêter la routine après 2 secondes

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 10, 2025, 11:44am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/2 "2025-02-10T11:44:59Z")

</div>

Is all of this code in Begin Routine? You seem to be resetting the variables and recreating the polygons every time.

---

<div class="post-metadata">

### Author: ![Clemence](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@Clemence](https://discourse.psychopy.org/u/Clemence)
#### Post date: [February 11, 2025, 8:25am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/3 "2025-02-11T08:25:24Z")

</div>

Some of it is in Each Frame, starting from `bar.width = progress * 1.0`.  
I tried using a new variable to avoid creating polygons every time, but it didn’t work.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 11, 2025, 9:37am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/4 "2025-02-11T09:37:31Z")

</div>

Either create the bar in Begin Experiment or create it as a Builder component. The latter is easier if the size only changes during one routine.

Are you using Builder?

---

<div class="post-metadata">

### Author: ![Clemence](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@Clemence](https://discourse.psychopy.org/u/Clemence)
#### Post date: [February 11, 2025, 9:41am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/5 "2025-02-11T09:41:59Z")

</div>

Yes, the bar is a polygon component in the Builder. However, using this component alone, I am unable to make it dynamically change on each trial based on correct or incorrect responses, right ?

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 11, 2025, 9:47am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/6 "2025-02-11T09:47:03Z")

</div>

> [@Clemence](#):
>
> bar = visual.Rect(win, width=progress, height=0.1, pos=[0, 0], fillColor=“gray”, lineColor=None)

Is this your code or created by the Builder component?

Polygon sizes can be changed dynamically Each Frame either by setting a variable or

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/8/4861cadae8c448b52504d9fd540953093ceb6b3b.png)

or using code:

```auto
polygon.setSize([newX,newY])

```

---

<div class="post-metadata">

### Author: ![Clemence](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@Clemence](https://discourse.psychopy.org/u/Clemence)
#### Post date: [February 11, 2025, 10:03am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/7 "2025-02-11T10:03:59Z")

</div>

This is part of my code.

Should I specify something particular in the “Layout” section of my component? I’ve updated it to set every frame (thank you!), but I’m unsure what to enter in the “size” field.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 11, 2025, 10:14am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/8 "2025-02-11T10:14:38Z")

</div>

Start by getting rid of any code related to bar.

Set the bar component fill colour to $barColor updating every frame.  
Set the bar component fill colour to [progress,.1] updating every frame.

Change bar.fillColor = “green” to barColor = “green”  
Change bar.fillColor = “red” to barColor = “red”

Is progress\_text a text component and a text object created in code?

---

<div class="post-metadata">

### Author: ![Clemence](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@Clemence](https://discourse.psychopy.org/u/Clemence)
#### Post date: [February 11, 2025, 10:27am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/9 "2025-02-11T10:27:59Z")

</div>

Thank you! I might have made a mistake here because I get the following error message:

```auto
bar.setFillColor(barColor[progress,.1], log=False)  
TypeError: string indices must be integers  
# Experiment ended with exit code 1 [pid:15452] # 

```

Yes, `progress_text` is a text component, but it is also created in the code. However, it works fine!

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 11, 2025, 10:41am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/10 "2025-02-11T10:41:42Z")

</div>

> [@wakecarter](#):
>
> Set the bar component fill colour to $barColor updating every frame.  
> Set the bar component fill colour to [progress,.1] updating every frame.

Sorry – my mistake

```auto
Set the bar component fill colour to $barColor updating every frame.
Set the bar component size to [progress,.1] updating every frame.

```

I would be interested to understand **why** you are creating the same text object in two different ways? Whichever gets created second will be replacing the first version.

---

<div class="post-metadata">

### Author: ![Clemence](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@Clemence](https://discourse.psychopy.org/u/Clemence)
#### Post date: [February 11, 2025, 10:52am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/11 "2025-02-11T10:52:27Z")

</div>

Thank you!

However, the bar still takes only three positions instead of continuously adjusting. If I get several correct answers in a row, it should increase significantly, but that is not happening.

Regarding the `progress_text`, I initially wrote the code first and then used the Builder, thinking I needed to link something from the code to a Builder component. In the end, I removed its part from the code and kept only the component, which now works perfectly!

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 11, 2025, 10:57am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/12 "2025-02-11T10:57:38Z")

</div>

If thew bar can only have three sizes and the size is [progress,.1] then please show any code related to progress, clarifying which tab the code is in. Unless told otherwise, I will assume that the code is at the top of the same routine as the bar.

---

<div class="post-metadata">

### Author: ![Clemence](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@Clemence](https://discourse.psychopy.org/u/Clemence)
#### Post date: [February 11, 2025, 11:04am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/13 "2025-02-11T11:04:05Z")

</div>

In begin routine, I set the progress as 0.5 `progress = 0.5`  
Same, in begin routine, if the reinforcement is positive, I use `progress = min(progress + step, 3.0)` ; but if the reinforcement is negative, I use `progress = max(progress - step, -3.0)`. I want limits between which the bar can go.

I don’t have anything related to progress in Each Frame.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 11, 2025, 11:27am UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/14 "2025-02-11T11:27:49Z")

</div>

If progress is supposed to be set only once per routine then put `progress = 0.5` in Begin Experiment so you don’t reset every trial and the bar size (and fill colour) can update every repeat instead of every frame.

---

<div class="post-metadata">

### Author: ![Clemence](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@Clemence](https://discourse.psychopy.org/u/Clemence)
#### Post date: [February 11, 2025, 1:50pm UTC](https://discourse.psychopy.org/t/progress-feedback-bar-using-a-polygon/43825/15 "2025-02-11T13:50:30Z")

</div>

Thank you so much it works !!
