using GUI dialog box

October 6th, 2006 mysurface Posted in X11, xmessage, zenity | Hits: 67529 | 8 Comments »

Every GUI program has its command line, even dialog boxes too. zenity for gnome, kdialog for KDE, xmessage for other windows managers, etc.

In this example I am going to show you examples of xmessage and zenity.

xmessage is a very simple dialog box which uses by fluxbox, it allows you to define your text and buttons. Let say I want to create a shutdown script, before execute the shutdown, I would like to ask for comfirmation.

xmessage  "Are you sure you want to shutdown? " -buttons yes,no

This will shows a simple dialog with 2 buttons, if user click yes, it returns 101, if no returns 102. To check the return value, do this

echo $?

You can ask xmessage to return the button label string, so you can store the label and manipulate the function.

answer=$(xmessage  "Are you sure you want to shutdown? " -buttons yes,no -print)

User click yes, answer will store “yes”. Checks the value with echo

echo $answer

zenity is more complete, it support various dialogs, question, notification, calendar, error etc. My example make use of question.

To load various types of dialog, just specified the types. Check the types by –help or simple man zenity. For this case, I want to use –question.

zenity --question --text "Are you sure you want to shutdown?"

The question dialog for zenity consist of “ok” and “cancel” buttons. Its button and return value are fixed. When user click “ok” it returns 0, “cancel” returns 1.

zenity allows you to specified you title.

zenity --title "Shutdown Comfirmation"
--question --text  "Are you sure you want to shutdown?"

Check out the sample scripts at Beyond the Sky

8 Responses to “using GUI dialog box”

  1. [...] With help of zenity, changing title for windows become very convenient.                              [...]

  2. [...] With help of zenity, you can even create a simple dialog to ask for a filename to save. [...]

  3. [...] 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. [...]

  4. Ultimate i have seen today!rearly amazing….can nyone tell me from where i can get the full step by step tutorial of zenity…thanks

  5. [...] [...]

  6. This is example dialog in perl: pastebin.com/f6fe3c4fd ;)

  7. The look for your web site is a tad off in Epiphany. Nevertheless I like your blog. I may need to use a normal web browser just to enjoy it.

Leave a Reply