# Gtk Signal\_connect and piping

**URL:** <https://discourse.julialang.org/t/gtk-signal-connect-and-piping/36829>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [April 1, 2020, 5:46am UTC](https://discourse.julialang.org/t/gtk-signal-connect-and-piping/36829 "2020-04-01T05:46:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Igor\_Fomenko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/igor_fomenko/32/13557_2.png) [@Igor\_Fomenko](https://discourse.julialang.org/u/Igor_Fomenko)\
**Post date:** [April 1, 2020, 5:46am UTC](https://discourse.julialang.org/t/gtk-signal-connect-and-piping/36829/1 "2020-04-01T05:46:23Z")

</div>

Hi, I decided to try piping instead of do-block but wo success

> using Gtk  
> b = GtkButton(“Press me”)  
> win = GtkWindow(b, “Callbacks”)  
> id = signal\_connect(b, “clicked”)|\>w-\>println(w, " was clicked!")  
> showall(win)

ERROR: MethodError: no method matching signal\_connect(::GtkButtonLeaf, ::String)  
what I did wrong?Thanks in advance

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [April 1, 2020, 8:32am UTC](https://discourse.julialang.org/t/gtk-signal-connect-and-piping/36829/2 "2020-04-01T08:32:29Z")

</div>

This is due to how pipes work: they call the function on the right with the value on the left, which is not what you want here: doing

```julia
signal_connect(b, "clicked") do w
    println(w, " was clicked")
end

```

is an alternative syntax for

```julia
signal_connect(w->println(w, " was clicked"), b, "clicked") 

```

In both cases the callback is passed as first argument, as required by `signal_connect`.

On the other hand, the following

```julia
signal_connect(b, "clicked") |> w->println(w, " was clicked!")

```

tries to execute `signal_connect(b, "clicked")` and pass the result to the function `w->println(w, " was clicked!")`. Another way to look at it: the following uses the pipe syntax correctly:

```julia
"hello" |> w->println(w, " was clicked!")

```

Obviously you cannot replace “hello” with the `signal_connect` call…

---

<div class="post-metadata">

**Author:** ![Igor\_Fomenko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/igor_fomenko/32/13557_2.png) [@Igor\_Fomenko](https://discourse.julialang.org/u/Igor_Fomenko)\
**Post date:** [April 1, 2020, 9:48am UTC](https://discourse.julialang.org/t/gtk-signal-connect-and-piping/36829/3 "2020-04-01T09:48:05Z")

</div>

I knew both forms you gave but I didn`t understand that anonim function after do statement become a part of signal\_connect function like in doc example with map function.

> map([A, B, C]) do x  
> if x \< 0 && iseven(x)  
> return 0  
> elseif x == 0  
> return 1  
> else  
> return x  
> end  
> end

I decided that with do-block map function send A,B,C to anonim function but it works as usual, applying anonim function to A,B,C.  
Many thanks.
