# Events on Julia

**URL:** <https://discourse.julialang.org/t/events-on-julia/73044>\
**Category:** New to Julia\
**Tags:** gtk, gui\
**Created:** [December 13, 2021, 6:55pm UTC](https://discourse.julialang.org/t/events-on-julia/73044 "2021-12-13T18:55:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cesarmarinhorj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cesarmarinhorj/32/30948_2.png) [@cesarmarinhorj](https://discourse.julialang.org/u/cesarmarinhorj)\
**Post date:** [December 13, 2021, 6:55pm UTC](https://discourse.julialang.org/t/events-on-julia/73044/1 "2021-12-13T18:55:41Z")

</div>

Julia has something like Events? “on” → “event” → callback  
thanks!

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [December 13, 2021, 7:35pm UTC](https://discourse.julialang.org/t/events-on-julia/73044/2 "2021-12-13T19:35:46Z")

</div>

No and maybe. The idea of event callbacks is inherently tied to GUI programming, and Julia has no built-in GUI functionality.

There are GUI packages, but I can’t answer to how any of them deal with callbacks. I would pick one first, and then figure out how it does this.

---

<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:** [December 13, 2021, 7:41pm UTC](https://discourse.julialang.org/t/events-on-julia/73044/3 "2021-12-13T19:41:17Z")

</div>

Observables.jl has observables with listeners and callbacks [https://github.com/JuliaGizmos/Observables.jl/](https://github.com/JuliaGizmos/Observables.jl/)

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [December 13, 2021, 7:43pm UTC](https://discourse.julialang.org/t/events-on-julia/73044/4 "2021-12-13T19:43:42Z")

</div>

As @gustaphe said, yes, this idea is not inherent to Julia’s base.  
However, the tool you’d probably want to look at (aside from @jules 's suggestion) is [GTK.jl](https://github.com/JuliaGraphics/Gtk.jl) if you are interested in GUI programming.

Example from docs here:

```julia
using Gtk

win = GtkWindow("My First Gtk.jl Program", 400, 200)

b = GtkButton("Click Me")
push!(win,b)

function on_button_clicked(w)
  println("The button has been clicked")
end
signal_connect(on_button_clicked, b, "clicked")

showall(win)

```

---

<div class="post-metadata">

**Author:** ![cesarmarinhorj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cesarmarinhorj/32/30948_2.png) [@cesarmarinhorj](https://discourse.julialang.org/u/cesarmarinhorj)\
**Post date:** [December 13, 2021, 11:07pm UTC](https://discourse.julialang.org/t/events-on-julia/73044/5 "2021-12-13T23:07:06Z")

</div>

I tried something with Reactive.jl, copy of its documentation.

```julia
using Reactive, Random, Printf

sigVotes = Signal(:NoVotes)
candidates = [:Alice, :Queen, :NoVotes]

aVotes = filter(v -> v == :Alice, sigVotes)
qVotes = filter(v -> v == :Queen, sigVotes)
nVotes = filter(v -> v == :NoVotes, sigVotes)

function count(cnt, _)
    cnt+1
end

aCount = foldp(count, 0, aVotes)
qCount = foldp(count, 0, qVotes)
nCount = foldp(count, 0, nVotes)

leading = map(aCount, qCount, nCount) do a, q, n
    if a == 0 || q == 0
        :NoVotes
    else
        if a > q
          :Alice
        elseif q > a
          :Queen
        else
          :Tie
        end
    end
end

function voting()
    for i in 1:100
        # change here, trigger to all
        push!(sigVotes, rand(candidates))
    end
    println(leading)
    println(@sprintf("Alice: %d x %d Queen (NoVotes: %d)", value(aCount), value(qCount), value(nCount)))
end

voting()

# vote again!
# voting()

```
