6

Zenity annoys me by always displaying the warning in terminal:

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

Apparently I'm not the only one:

Almost all the answers tell you to change the way you call zenity by appending 2>/dev/null to the end of the command. I don't want to do this to all the code I've already written and remember this for future code I write.

Is there an easier way of making this annoying message disappear?

1

3 Answers 3

6

Update 2019-05-17: OP has found another resolution along the same method presented here via global redirection by use of exec command. Please refer to linked duplicate post for more info

Basically, there's no other way except redirecting stderr to /dev/null. The main reason is because Gtk requires dialog windows ( which is what zenity windows actually are ) to have a parent application window. This same thing happens if you build GUI dialog from scratch in c or python.

Thus, the only "real" way is for Gtk developers to actually allow dialog windows to stand on their own, or zenity developers to silence those warning from within their source code. Otherwise, your only option is to constantly add 2>/dev/null to any zenity command. Of course you can always make an alias or wrapper function that will do it for you, something along the lines of this:

zenity(){
    /usr/bin/zenity "$@" 2>/dev/null
}

This, however, may have issues with quoting and passing arguments, but for the most part should work. If you work in Python or another language that can actually handle Gtk, you can brew your own popup dialogs with hidden parent windows, which comes at the cost of complexity and learning how to create those things. But again, the real way would be for zenity developers actually fix this or Gtk developers to acknowledge the need for standalone dialog windows.

3
  • When researching the question I read somewhere developers were working on making this warning go away. When was not addressed though.... Mar 26, 2017 at 2:41
  • This may have issues with quoting, especially since you used mismatched quotes.
    – anon
    Mar 26, 2017 at 6:58
  • @QPaysTaxes ooops, thanks for catching the mismatched quotes. Was typing without glasses Mar 26, 2017 at 7:33
6

Automatically add 2>/dev/null every time zenity is called

Edit the file ~/.bashrc and search for these lines:

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

Add the following lines after:

# Add zenity alias to make the annoying terminal error message disappear forever:
# "Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged."
alias zenity="zenity 2>/dev/null"

Save the file and open a new terminal window to test:

zenity --info --text "Hello Zenity-Silly-Error-Free World"

Voila! All your old code is fixed and future code doesn't need to have 2>/dev/null appended to it like all the other answers instruct.

16
  • Why would you use sudo powers to edit your own bashrc? Mar 26, 2017 at 1:55
  • @AndreaLazzarotto fixed that ;) Mar 26, 2017 at 1:58
  • "...future code doesn't need to have 2>/dev/null appended to it like all the other answers instruct". Well, it still effectively has redirection appended to it each time, you just don't do it by hand. Mar 26, 2017 at 2:02
  • 1
    @AndreaLazzarotto You are so right. Sorry my mind has been conditioned to put sudo into all my posts. Bad habits are hard to break... Mar 26, 2017 at 2:16
  • 1
    In bash, aliases are not evaluated except when called in response to user command input or by using special shell variables, nor is .bashrc sourced when executed from a script (non-interactively). Since the primary use of zenity is scripting, this answer doesn't make a lot of sense to me. May 17, 2019 at 12:44
3

I prefer to edit ~/.bashrc with:

alias zenity="zenity 2> >(grep -v 'GtkDialog' >&2)"

This is more restrictive, inhibits only the warning messages that have the GtkDialog string, leaving the other error or warning messages to be displayed

1
  • It works! The only problem is that another warning is generated in Ubuntu 18.04: (zenity:6984): GLib-WARNING **: 14:59:39.494: ../../../../glib/giounix.c:410Error while getting flags for FD: Bad file descriptor (9)
    – f0nzie
    Feb 12, 2020 at 21:01

Not the answer you're looking for? Browse other questions tagged .