# Open\_dialog with a transient parent

**URL:** <https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 26, 2018, 10:34am UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334 "2018-02-26T10:34:56Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 26, 2018, 10:34am UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/1 "2018-02-26T10:34:56Z")

</div>

How _exactly_ do I use `Gtk.open_dialog` from [Gtk](https://github.com/JuliaGraphics/Gtk.jl) with a parent, and avoid this:

```julia
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.

```

Any MWE would be great, thanks!

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [February 26, 2018, 11:39am UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/2 "2018-02-26T11:39:35Z")

</div>

How do you user open\_dialog right now?

> **[Gtk-3.0](https://docs.gtk.org/gtk3/)**
>
> Reference for Gtk-3.0

has a paragraph about  
gtk\_window\_set\_transient\_for ()  
and i’d guess this should be used to give a modal window like the dialog a parent.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 26, 2018, 11:51am UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/3 "2018-02-26T11:51:26Z")

</div>

> [@lobingera](#):
>
> gtk\_window\_set\_transient\_for ()

Thanks for the tip, but I’m still not sure how I can specify that there is no parent window. What I do now is:

```julia
txtfile = open_dialog("Pick a `.txt` file", Null(), ("*.txt",))

```

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [February 26, 2018, 11:56am UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/4 "2018-02-26T11:56:43Z")

</div>

and open\_dialog is from where?

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 26, 2018, 12:06pm UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/5 "2018-02-26T12:06:33Z")

</div>

> [@lobingera](#):
>
> and open\_dialog is from where?

OMG, sorry: [Gtk](https://github.com/JuliaGraphics/Gtk.jl).

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [February 26, 2018, 12:23pm UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/6 "2018-02-26T12:23:52Z")

</div>

[https://github.com/JuliaGraphics/Gtk.jl/blob/5d12682c9ffa75f7ff5e24d352643e61d9ce10ba/docs/src/manual/filedialogs.md](https://github.com/JuliaGraphics/Gtk.jl/blob/5d12682c9ffa75f7ff5e24d352643e61d9ce10ba/docs/src/manual/filedialogs.md) says the second argument is the parent container.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 26, 2018, 12:28pm UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/7 "2018-02-26T12:28:16Z")

</div>

Yea, but if I use their example, I still get that warning:

```julia
julia> using Gtk

julia> open_dialog("title", GtkNullContainer(), String[])
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.

```

Maybe there is no way to circumvent that warning?

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [February 26, 2018, 12:32pm UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/8 "2018-02-26T12:32:00Z")

</div>

The warning is there, because a Null container is somehow a non-window and therefore the parent is missing. Digging a little bit deeper: the warning shows up to inform you, that with a setup like this your window manager might not be able to manage the dialog window which can have strange side effects like sticking on your screen (happens a lot with tool tips from Gtk on windows).

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 26, 2018, 12:34pm UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/9 "2018-02-26T12:34:29Z")

</div>

I see. So it’s there to stick, unless I give it a real parent. But is there a clean simple way to do that? Like what would be the correct way to use `open_dialog` if that is the only need we have to communication with the user?

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [February 26, 2018, 12:48pm UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/10 "2018-02-26T12:48:21Z")

</div>

Afair (i haven’t done gtk application development for some time), a well behaving gtk GUI application should have an top-level application window to which you add menu, dialogs etc. If you only call open\_dialog to ask for input and your application is terminal only, i’d guess you can live with the warning.

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [February 26, 2018, 1:38pm UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/11 "2018-02-26T13:38:26Z")

</div>

yes, this is the way I do this as well. The advantage when passing the top-level window is that one can set the dialog to be modal.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 26, 2018, 1:40pm UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/12 "2018-02-26T13:40:38Z")

</div>

It makes sense. I guess one way “around it” is to open a transparent window as a default parent and kill it with the dialog.

---

<div class="post-metadata">

**Author:** ![Carsten](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Carsten](https://discourse.julialang.org/u/Carsten)\
**Post date:** [December 29, 2018, 2:31pm UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/13 "2018-12-29T14:31:55Z")

</div>

I‘ve got a similar (same) problem when I carry out the following steps:  
_Step 1_  
Loading the main program. Opening the main GtkWindow.

_Step 2_  
Try to open a file via a button (→ load a file) which opens the dialog box:  
as a result: the loading action sticks with a message:

Gtk-Message: 14:40:16.416: GtkDialog mapped without a transient parent. This is discouraged.

_Step 3_  
Now loading the file from console without closing the GtkWindow:

julia\> file = open\_dialog(“Pick a file”, Null(), (“\*.jld2”,))  
Gtk-Message: 14:43:52.239: GtkDialog mapped without a transient parent. This is discouraged.  
“D:\WORK\ResultsNew\233=010.jld2”  
julia\> load\_para1(file)  
load\_profilemodel\_type(): \>\>\>\>\>\>\>\>\>\>\>\>\> 233=010  
load\_para1(file): \>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\> done  
julia\>

All parameter loaded!

_Step 4_  
Set the focus on the main GtkWindow. Repeat the loading process via button and the open\_dialog box. Now, all data are loaded **without** a message:

Gtk-Message: 14:43:52.239: GtkDialog mapped without a transient parent. This is discouraged.

What‘s wrong? Is there a workaround to get rid of the Gtk-WARNING message?

Same behavior if I apply:

file = open\_dialog("Choose a file", GtkNullContainer(), ("\*.jld2, \*.jl",), select\_multiple=false)

(btw. What the difference between Null() vs GtkNullContainer() ?)

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [December 29, 2018, 8:33pm UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/14 "2018-12-29T20:33:18Z")

</div>

you should pass the GtkWindow from your main program as the second argument to the `open_dialog`. Then you won’t get the warning.

---

<div class="post-metadata">

**Author:** ![Carsten](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Carsten](https://discourse.julialang.org/u/Carsten)\
**Post date:** [December 29, 2018, 11:03pm UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/15 "2018-12-29T23:03:51Z")

</div>

👏

---

<div class="post-metadata">

**Author:** ![rverdier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rverdier/32/9104_2.png) [@rverdier](https://discourse.julialang.org/u/rverdier)\
**Post date:** [February 15, 2019, 1:54am UTC](https://discourse.julialang.org/t/open-dialog-with-a-transient-parent/9334/16 "2019-02-15T01:54:55Z")

</div>

```julia
# Test of Julia-Gtk messaging
using Gtk
win = GtkWindow("Test")
res = ask_dialog("Hello", win, "OK", "No") && println("Done.")
# This gives the fatal error
#=(<unknown>:2724): Gtk-CRITICAL **: 20:46:30.936: gtk_message_dialog_new: assertion 'parent == NULL || GTK_IS_WINDOW (parent)' failed
ERROR: LoadError: Cannot construct GtkMessageDialogLeaf with a NULL pointer
=#
res = ask_dialog("Hello", "OK", "No") && println("Done.")
# This works but gives the warning
# Gtk-Message: 20:47:24.154: GtkDialog mapped without a transient parent. This is discouraged.

```

How should the first one be modified to work?
