# How to animate a slider in GLMakie?

**URL:** <https://discourse.julialang.org/t/how-to-animate-a-slider-in-glmakie/83151>\
**Category:** New to Julia\
**Tags:** glmakie\
**Created:** [June 21, 2022, 10:33pm UTC](https://discourse.julialang.org/t/how-to-animate-a-slider-in-glmakie/83151 "2022-06-21T22:33:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Willi\_Wespe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willi_wespe/32/36558_2.png) [@Willi\_Wespe](https://discourse.julialang.org/u/Willi_Wespe)\
**Post date:** [June 21, 2022, 10:33pm UTC](https://discourse.julialang.org/t/how-to-animate-a-slider-in-glmakie/83151/1 "2022-06-21T22:33:39Z")

</div>

Hi,  
I want to animate a slider when I press a button.  
The slider should move from a start value to an end value, but it jumps right to the end, though I use sleep, and checked that the for loop works correct.

```julia
using GLMakie

fig = Figure(resolution=(1200, 700))
ax = Axis(fig[1, 1])

sliderT = Slider(fig[2, 1], range = 1:25, startvalue = 1)

fig[3, 1] = buttongrid = GridLayout(tellwidth = false)
button = buttongrid[1, 1] = Button(fig, label = "▶ / ||")

on(button.clicks) do _

    # Somewhere here's the problem I guess
    for i in 1:20
        set_close_to!(sliderT, i)
        sleep(0.01)
        println(i)
    end
    
end

display(fig)

```

Do you have any ideas?  
Thanks

---

<div class="post-metadata">

**Author:** ![AndiMD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andimd/32/6531_2.png) [@AndiMD](https://discourse.julialang.org/u/AndiMD)\
**Post date:** [June 22, 2022, 12:39am UTC](https://discourse.julialang.org/t/how-to-animate-a-slider-in-glmakie/83151/2 "2022-06-22T00:39:01Z")

</div>

Running asynchronously allows the figure to update.  
`@async for i in 1:20`

---

<div class="post-metadata">

**Author:** ![Willi\_Wespe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willi_wespe/32/36558_2.png) [@Willi\_Wespe](https://discourse.julialang.org/u/Willi_Wespe)\
**Post date:** [June 22, 2022, 7:35am UTC](https://discourse.julialang.org/t/how-to-animate-a-slider-in-glmakie/83151/3 "2022-06-22T07:35:57Z")

</div>

It works perfectly, thank you very much!
