# How to connect an event handler to a button in Makie.jl?

**URL:** <https://discourse.julialang.org/t/how-to-connect-an-event-handler-to-a-button-in-makie-jl/53851>\
**Category:** Visualization\
**Tags:** question\
**Created:** [January 24, 2021, 2:41am UTC](https://discourse.julialang.org/t/how-to-connect-an-event-handler-to-a-button-in-makie-jl/53851 "2021-01-24T02:41:06Z")\
**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:** [January 24, 2021, 2:41am UTC](https://discourse.julialang.org/t/how-to-connect-an-event-handler-to-a-button-in-makie-jl/53851/1 "2021-01-24T02:41:07Z")

</div>

How can I execute a function when I press a button in Makie?

This is missing in the documentation.

Example:

```julia
using GeometryBasics, GLMakie

function reset()
    # set camera and zoom to default values
end

function main()
    scene, layout = layoutscene(resolution = (800, 900), backgroundcolor = RGBf0(0.7, 0.8, 1))
    scene3D = LScene(scene, scenekw = (show_axis=false, limits = Rect(-7,-10.0,0, 11,10,11), resolution = (800, 800), camera = cam3d_cad!, raw = false))

    layout[1, 1] = scene3D
    layout[2, 1] = buttongrid = GridLayout(tellwidth = false)

    buttongrid[1, 1:3] = [Button(scene, label = "RESET"), Button(scene, label = "Zoom +"), Button(scene, label = "Zoom -")]
    return scene
end

```

I want that the function reset() is called when I click the button “RESET”.

Full code available at: [https://github.com/ufechner7/KiteViewer](https://github.com/ufechner7/KiteViewer)

---

<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:** [January 24, 2021, 3:47am UTC](https://discourse.julialang.org/t/how-to-connect-an-event-handler-to-a-button-in-makie-jl/53851/2 "2021-01-24T03:47:47Z")

</div>

Huh you’re right. The button has a `clicks` attribute that counts clicks which you can lift / on

```julia
on(button.clicks) do c
    println("pressed $c times")
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:** [January 24, 2021, 8:38am UTC](https://discourse.julialang.org/t/how-to-connect-an-event-handler-to-a-button-in-makie-jl/53851/3 "2021-01-24T08:38:11Z")

</div>

This is indeed working. So simple!

Perhaps it can be added to the documentation.

---

<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:** [January 24, 2021, 9:13am UTC](https://discourse.julialang.org/t/how-to-connect-an-event-handler-to-a-button-in-makie-jl/53851/4 "2021-01-24T09:13:47Z")

</div>

~~I will add an example soon~~ I have tagged new docs with an updated example
