A complete zenity dialog examples 1

April 22nd, 2007 mysurface Posted in X11, zenity | Hits: 303176 | 28 Comments »

Zenity is a tool that help you to create a common functional GTK+ dialogs. It have various dialogs that each of them have different ways of presenting data and acquire data from user input.

We have introduce how to make use of GUI dialog box in Using GUI dialog box, where we give an example of how zenity create a question dialog box. Besides question dialog box, zenity can create more than that, such as calendar, entry, error, info, file selection, list, notification, progress, warning, scale and text info. In this tutorial, we would like to illustrate how to create every single zenity dialog by examples.

How to create zenity calendar dialog?
You are allow to specify the initial selection of date in calendar dialog, specified with options –day –month –year. The default selection will be today’s date. Zenity will returns the date selected by user.

szDate=$(zenity --calendar --text "Pick a day" --title "Medical Leave" --day 23 --month 5 --year 2008); echo $szDate

zenity calendar dialog

How to create zenity entry dialog?
Entry dialog usually use to acquire string entry from user.

szAnswer=$(zenity --entry --text "where are you?" --entry-text "at home"); echo $szAnswer

zenity entry dialog

How to create zenity error dialog?
Create an error dialog is straight forward, it does not wait for user input.

zenity --error --text "Installation failed! "

zenity error dialog

How to create zenity info dialog?

zenity --info --text "Join us at irc.freenode.net #lbe."


zenity info dialog

How to create zenity File Selection dialog?
File selection dialog is one of the a very useful zenity dialog, it support open file or save file dialog. The best part is, zenity file selection dialog is not difficult to use. Let me show you how to create a save file dialog box, if filename already exists, it will ask for confirmation.

szSavePath=$(zenity --file-selection --save --confirm-overwrite);echo $szSavePath

zenity file selection dialog
Check out more and try to create an open file dialog yourself?

zenity --help-file-selection

How to create zenity notification dialog?
To notify users regarding to some status, you can use notification dialog, a tiny icon will be appear at taskbar.

zenity  --notification  --window-icon=update.png  --text "Please update your system."

Next coming up tutorial will covers zenity dialog such as progress, question, warning, scale, text-info and list.

Check out A complete zenity dialog examples 2.

28 Responses to “A complete zenity dialog examples 1”

  1. […] This is a continues post of A complete zenity dialog examples 1, in this post we will covers zenity dialog for progress, question, warning, scale, text info and list. […]

  2. jojolafrite Says:

    thanks I had some troubles to understand some tricks about zenity. this was really usefull. I’m now going to read about awk … gret site.

  3. Wow, good work! These examples helped me a lot, thanks!

  4. Il seguente script è solo un esempio per mostrare alcuni componenti richiamabili attraverso zenity

    zenity –question –text “Vuoi editare un nuovo file?”
    if [ $? = 0 ];
    SELECTED_FILE=`zenity –file-selection`
    zenity –text-info –width=560 –editable –filename=$SELECTED_FILE > $SELECTED_FILE.edited
    echo “Saved $SELECTED_FILE as $SELECTED_FILE.edited”
    zenity –text-info –filename=$SELECTED_FILE.edited

  5. really usefull post!

  6. cool

  7. thanks, good post!

  8. […] dialogs for multi purpose usage, this tutorial illustrate the usage of each dialogs by examples.https://linux.byexamples.com/archives/259/a-complete-zenity-dialog-examples-1/PyGTK 2.0 TutorialThis tutorial describes the use of the Python PyGTK […]

  9. Nice post! We’re for sure linking you back!

  10. […] allways use "zenity" your script can bring up a series of simple 1 line input boxes. Zenity examples it basically works by putting "var=$(zenity –entry –text "Does this work")", […]

  11. Thanks!
    You can also give a title to the file save command:
    –title “Save as…”

  12. how can we put 2 zenity entry dialogs in 1 box???

  13. dialog vs zenity, which one will you prefer?

  14. Martin Sydenham Says:

    Second that question about how to zenity entry dialogs in 1 box (e.g. to choose an input and output directory)?

  15. Is it possible to have an entry box with a listed file in it? For example:

    Question 1
    Question 2
    Question 3
    Question 4

    Enter your answers for above questions:
    <Input Field.

  16. […] ist mit Programmen wie zenity, kdialog oder notify-send auf prinzipiell kein Problem. Doof ist nur, wenn man möchte, dass einem […]

  17. how does this –progress option work? i want to execute a command when progress bat is full.

    thank you
    (reply to verwijs.pc@gmail.com)

  18. oops “bat” = “bar” :)

  19. […] Zenity ???????? ????? ?????????? ??? ? ??? ? ??????? ?????? ??????????? ??? ????????? […]

  20. I have been exploring for a little for any high-quality articles or weblog posts on this sort of area . Exploring in Yahoo I eventually stumbled upon this website. Studying this information So i’m glad to show that I have a very good uncanny feeling I found out exactly what I needed. I so much indisputably will make certain to don’t omit this website and give it a glance on a continuing basis.

  21. Hmm it looks like your website ate my first comment (it was
    super long) so I guess I’ll just sum it up what I wrote
    and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog
    writer but I’m still new to the whole thing. Do you have any points for newbie blog writers? I’d definitely
    appreciate it.

  22. I know this web site offers quality depending content and extra information, is there any other website which offers such data in quality?

  23. Appuyez dessus et le panneau de commande hack

  24. Example for –file-Filter:
    zenity –file-selection –file-filter=’Music files (ogg,wav,aac) | *.ogg *.wav *.aac’ –file-filter=’All files | *’


  25. Yes, thanks for providing these zenity examples–very helpful!

    Cheers, Sam

  26. How do you suppress X (cancel) button in this dialogs? Thanks

  27. replying to number 26 acg asking how to press the “x” and cancel buttons on zenity. I assume your saying how to make them functional. What you want is an if statement. If you run a set -x on your script and select cancel you can see that the script will output a (1 eq 1) or (0 eq 1) statement. you will need to make an if statement that is something like this:

    if [$? eq 1]; then
    #whatever command you would like to follow if cancel

    I would recommend an zenity –error window to show the cancelation. something like

    zenity –error –title “canceled” #whatever dialog you would like to include.

    Now this is from memory so the exact layout may be a little different but that is how you can get the “X” and “cancel” buttons to function

  28. Hi, how i can use a list with the form ?

    I want add in a form :

    text input
    text input
    list with options
    text input
    list with options …

Leave a Reply