# How to toggle a button with Makie.jl?

**URL:** <https://discourse.julialang.org/t/how-to-toggle-a-button-with-makie-jl/60381>\
**Category:** Visualization\
**Tags:** question, makie\
**Created:** [May 1, 2021, 2:11pm UTC](https://discourse.julialang.org/t/how-to-toggle-a-button-with-makie-jl/60381 "2021-05-01T14:11:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 1, 2021, 2:11pm UTC](https://discourse.julialang.org/t/how-to-toggle-a-button-with-makie-jl/60381/1 "2021-05-01T14:11:41Z")

</div>

I have a 3D viewer written in MakieGL. I have a button “PLAY”, and I want it to change to a “PAUSE” button when clicked and back to a “PLAY” button when clicked again.

How can I achieve that?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [May 1, 2021, 2:43pm UTC](https://discourse.julialang.org/t/how-to-toggle-a-button-with-makie-jl/60381/2 "2021-05-01T14:43:17Z")

</div>

You can for example use an observable to track the play/pause state and lift the button label off of that.

```julia
running = Node(false)

function toggle_running()
    running[] = !running[] # or more complex logic
end

b = Button(..., label = @lift($running ? "PAUSE" : "PLAY"))

on(b.clicks) do _
    toggle_running()
end

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 1, 2021, 3:46pm UTC](https://discourse.julialang.org/t/how-to-toggle-a-button-with-makie-jl/60381/3 "2021-05-01T15:46:34Z")

</div>

Works nicely!

Complete example:

```julia
using GLMakie

running = Node(false)

function toggle_running()
    running[] = !running[] # or more complex logic
end

fig=Figure()
fig[2, 1] = buttongrid = GridLayout(tellwidth = false)
btn = Button(fig, label = @lift($running ? "PAUSE" : "PLAY"))
buttongrid[1, 1:1] = [btn]

on(btn.clicks) do _
    toggle_running()
end

gl_screen = display(fig)
wait(gl_screen)

return nothing

```

---

<div class="post-metadata">

**Author:** ![RobbesU](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robbesu/32/212459_2.png) [@RobbesU](https://discourse.julialang.org/u/RobbesU)\
**Post date:** [February 12, 2025, 7:26am UTC](https://discourse.julialang.org/t/how-to-toggle-a-button-with-makie-jl/60381/4 "2025-02-12T07:26:03Z")

</div>

For info: In my current GLMakie (V0.10.18): `Node`s are now called `Observable`s (in line with Observables.jl)

> **[Observables | Makie](https://docs.makie.org/stable/explanations/observables#The-Observable-structure)**
>
> Create impressive data visualizations with Makie, the plotting ecosystem for the Julia language. Build aesthetic plots with beautiful customizable themes, control every last detail of publication quality vector graphics, assemble complex layouts and...

Historic link to Makie docs with Node: [Observables & Interaction](https://docs.makie.org/v0.15/documentation/nodes/)
