# GLMakie: how to refresh Menu object when item is selected via code?

**URL:** <https://discourse.julialang.org/t/glmakie-how-to-refresh-menu-object-when-item-is-selected-via-code/90341>\
**Category:** General Usage\
**Tags:** makie, glmakie\
**Created:** [November 16, 2022, 11:47am UTC](https://discourse.julialang.org/t/glmakie-how-to-refresh-menu-object-when-item-is-selected-via-code/90341 "2022-11-16T11:47:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Post date:** [November 16, 2022, 11:47am UTC](https://discourse.julialang.org/t/glmakie-how-to-refresh-menu-object-when-item-is-selected-via-code/90341/1 "2022-11-16T11:47:59Z")

</div>

Consider the following code

```julia
using GLMakie

fig = Figure()
b = Button(fig, label="Select ABC", textsize=20)
m = Menu(fig, options=zip(["A", "AB", "ABC"], 1:3), default="A", textsize=20)
panel = GridLayout()
panel[:v] = [b, m]
fig[1,1] = panel

on(b.clicks) do n
    # It seems you can pass any value to m.selection
    m.selection[] = "ABC"
end

on(m.selection) do idx
    println(idx) # it will print "ABC" when the button clicks
end

```

When the button is clicked, the listener of `m.selection` is triggered. However, the `Menu` object displayed in the figure still shows that the item “A” is selected but not “ABC”.

My question is: what can I do to let the menu selected item reflect the button click? Thanks!

---

<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:** [November 16, 2022, 12:45pm UTC](https://discourse.julialang.org/t/glmakie-how-to-refresh-menu-object-when-item-is-selected-via-code/90341/2 "2022-11-16T12:45:49Z")

</div>

I think you can set `m.i_selected = j` where j is the index of the option, but that was not intended to be public API (it even says so in the docstring).

---

<div class="post-metadata">

**Author:** ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Post date:** [November 16, 2022, 12:49pm UTC](https://discourse.julialang.org/t/glmakie-how-to-refresh-menu-object-when-item-is-selected-via-code/90341/3 "2022-11-16T12:49:27Z")

</div>

Thanks! It works. Though it is weird in the doc [https://docs.makie.org/v0.18.2/examples/blocks/menu/](https://docs.makie.org/v0.18.2/examples/blocks/menu/)  
It says:

> `i_selected`: Index of selected item. Should not be set by the user. Default: `0`
