How to make zenity "transient parent" warning disappear permanently

5,492

Solution 1

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.

Solution 2

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.

Solution 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

Share:
5,492

Related videos on Youtube

WinEunuuchs2Unix
Author by

WinEunuuchs2Unix

Software development is my main hobby. Check out the new websites created in October 2021: www.pippim.com and pippim.github.io

Updated on September 18, 2022

Comments

  • WinEunuuchs2Unix
    WinEunuuchs2Unix almost 2 years

    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?

  • Andrea Lazzarotto
    Andrea Lazzarotto over 7 years
    Why would you use sudo powers to edit your own bashrc?
  • Sergiy Kolodyazhnyy
    Sergiy Kolodyazhnyy over 7 years
    @AndreaLazzarotto fixed that ;)
  • Sergiy Kolodyazhnyy
    Sergiy Kolodyazhnyy over 7 years
    "...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.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 7 years
    @AndreaLazzarotto You are so right. Sorry my mind has been conditioned to put sudo into all my posts. Bad habits are hard to break...
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 7 years
    When researching the question I read somewhere developers were working on making this warning go away. When was not addressed though....
  • Nic
    Nic over 7 years
    This may have issues with quoting, especially since you used mismatched quotes.
  • Sergiy Kolodyazhnyy
    Sergiy Kolodyazhnyy over 7 years
    @QPaysTaxes ooops, thanks for catching the mismatched quotes. Was typing without glasses
  • Elder Geek
    Elder Geek almost 7 years
    Simple and effective. I like it.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix almost 7 years
    @ElderGeek Thanks for the compliment. Should I accept my answer over Serg's then? I was waiting for input to recuse myself.
  • Elder Geek
    Elder Geek almost 7 years
    That's your call, not mine. It looks like your answer preceded his, both answers have value.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix almost 7 years
    @ElderGeek Mine proceeds his only because I posted both the question and answer at the same time making it unfair. I'll wait to see how others vote and accept the most popular. Right now it appears tied although I did upvote his answer :)
  • Elder Geek
    Elder Geek almost 7 years
    As did I so. IMHO your answer is more useful for the average user and his is more useful for those who program and recognize a function/method when they see one.
  • Andrew Domaszek
    Andrew Domaszek about 5 years
    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.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix about 5 years
    @AndrewDomaszek Thanks for pointing this out. I've changed the accepted answer from my own to Serge. I should have done it two years ago when Elder Geek commented.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix about 5 years
    @ElderGeek Thank you for your comments I've FINALLY acted upon them and changed accepted answer :)
  • datacarl
    datacarl over 4 years
    I don't see the reason why you would put it below the ls-aliases. It's not affected by them, nor does it affect those. Where is the relation? The alias would be as fine in the second line or the last line, wouldn't it?
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 4 years
    @userunknown I prefer to put user aliases below system aliases. Functionally it makes no difference but from a maintenance point of view and porting to new installs, I like to keep installation code above and custom code below.
  • datacarl
    datacarl over 4 years
    These aren't system aliases, since they are in the users .bashrc file. It's just a default suggestion. To have a system how to organize your aliases (some keep all of them in a separate file) is fine and I wouldn't suggest changing your habit. But a newbie can't infer that from your answer and might think there is some importance to this, that there is an effect. Ha, I just wanted to point out, that the TO, which is WinEunuuchs2Unix, seems not to need such advice with his high reputation, but that's you too. :) OK - keep the good work going.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 4 years
    @userunknown Answer was written when reputation was low and I was still a relative beginner in Ubuntu/Linux.. By "system alias" I mean the Ubuntu installation created the alias. As far as new users go if they are keen enough they will read your comments to gain a greater understanding. If they do not read your comments and place alias where answer suggests no harm will come about.
  • f0nzie
    f0nzie over 4 years
    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)