We explain every GNU/Linux command by examples in this blog!

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.

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