# Problem with GUI ask\_dialog

**URL:** https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224
**Category:** General Usage
**Tags:** question, guis, gtk
**Created:** [December 16, 2021, 7:14pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224 "2021-12-16T19:14:38Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [December 16, 2021, 7:14pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/1 "2021-12-16T19:14:39Z")

</div>

Julia is freezing when I use `ask_dialog()` in julia file. I added extra code as suggested to let it work, however, the problem is still existing. Any solution?

```julia
using Gtk
win = GtkWindow("gtkwait")
if !isinteractive()
    @async Gtk.gtk_main()
    Gtk.waitforsignal(win,:destroy)
  end
  state = ask_dialog("Like or Not?", "No", "Yes")

```

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [December 20, 2021, 2:44pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/2 "2021-12-20T14:44:02Z")

</div>

Any solution?

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [December 20, 2021, 2:55pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/3 "2021-12-20T14:55:36Z")

</div>

Try ensuring it runs in the UI thread by putting it in an `Gtk.@idle_add begin ... end` block.

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [December 20, 2021, 2:58pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/4 "2021-12-20T14:58:20Z")

</div>

Also, I think the `Gtk.waitforsignal` call is only intended for the end of a script?

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [December 20, 2021, 4:17pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/6 "2021-12-20T16:17:50Z")

</div>

I think you can ignore `@idle_add` for now, it looks like, based on the documentation, you need to put the `ask_dialog` _first_, and then at the _end_ of the script, do the `if !isinteractive` block.

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [December 20, 2021, 4:46pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/8 "2021-12-20T16:46:44Z")

</div>

Ah, I see the issue. Sorry, just trying it out myself.

It’s not that it gets frozen per se, it’s that the dialog button press isn’t registering somehow, so the dialog never closes and allows the program to continue.

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [December 20, 2021, 4:47pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/9 "2021-12-20T16:47:54Z")

</div>

Might be related to this issue: [https://github.com/JuliaGraphics/Gtk.jl/issues/576](https://github.com/JuliaGraphics/Gtk.jl/issues/576)

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [December 20, 2021, 4:51pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/10 "2021-12-20T16:51:54Z")

</div>

Thank you!

> [@BioTurboNick](#):
>
> Might be related to this issue: [Hangs when calling open\_dialog()/open\_dialog\_native() non-interactively · Issue #576 · JuliaGraphics/Gtk.jl · GitHub](https://github.com/JuliaGraphics/Gtk.jl/issues/576)

Unfortunately, I did not find a solution at this link.

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [December 20, 2021, 4:54pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/11 "2021-12-20T16:54:46Z")

</div>

Right, it may need people to look more deeply into what’s going on. I might be able to poke around but I’m not the most familiar with the code base.

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [December 20, 2021, 5:04pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/12 "2021-12-20T17:04:51Z")

</div>

@JeffFessler JeffFessler  
Can you support please?

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [December 20, 2021, 5:10pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/13 "2021-12-20T17:10:01Z")

</div>

Oh no… this is a Heisenbug. If you stick `println`s in the function, it starts working 😆

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [December 20, 2021, 5:30pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/15 "2021-12-20T17:30:09Z")

</div>

Sorry, I mean in the Gtk.jl function itself. But, you can call the internal functions directly and it seems to work:

```julia
    dlg = GtkMessageDialog(message, ((no_text, 0), (yes_text, 1)),
            Gtk.GtkDialogFlags.DESTROY_WITH_PARENT, Gtk.GtkMessageType.QUESTION, Gtk.GtkNullContainer())
    println("I'm necessary for some reason")
    response = run(dlg)
    destroy(dlg)
    status = response == 1

```

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [December 20, 2021, 5:35pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/17 "2021-12-20T17:35:41Z")

</div>

See my edited post

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [December 20, 2021, 5:39pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/18 "2021-12-20T17:39:15Z")

</div>

Many thanks for your help. It works!

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [December 20, 2021, 6:37pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/19 "2021-12-20T18:37:04Z")

</div>

A better solution was posted in the GitHub issue you could try.

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [December 20, 2021, 6:40pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/20 "2021-12-20T18:40:27Z")

</div>

Thank you, I will have a look

---

<div class="post-metadata">

### Author: ![tknopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tknopp/32/3569_2.png) [@tknopp](https://discourse.julialang.org/u/tknopp)
#### Post date: [December 20, 2021, 6:47pm UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/21 "2021-12-20T18:47:59Z")

</div>

for the records: Here is what you want if you are using Gtk in an interactive/still scripted manner:

```julia
using Gtk
  
if !isinteractive()
    @async Gtk.gtk_main()
end

t = @async begin
  state = ask_dialog("Find Steady-state solution and start rom steady-state?", "No", "Yes")
end

if !isinteractive()
    wait(t)
end

```

---

<div class="post-metadata">

### Author: ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)
#### Post date: [August 17, 2022, 9:01am UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/22 "2022-08-17T09:01:28Z")

</div>

Another issue is the problem that occurs when you work with multiple monitors.  
Is it possible that the pop-up window opens on the same monitor, where the REPL is located?

---

<div class="post-metadata">

### Author: ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)
#### Post date: [September 23, 2022, 8:44am UTC](https://discourse.julialang.org/t/problem-with-gui-ask-dialog/73224/23 "2022-09-23T08:44:46Z")

</div>

Meanwhile I found a [thread that shows how to count the number of available monitors and select a monitor to display a window](https://github.com/JuliaGraphics/Gtk.jl/issues/631), this is already great.  
Now it would be nice to figure out on which monitor my current `REPL`-window is located,  
has someone a suggestion?
