using GUI dialog box
October 6th, 2006 mysurface Posted in X11, xmessage, zenity | Hits: 59769 | 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







December 15th, 2006 at 8:49 am
[...] With help of zenity, changing title for windows become very convenient. [...]
February 3rd, 2007 at 5:53 am
[...] With help of zenity, you can even create a simple dialog to ask for a filename to save. [...]
April 22nd, 2007 at 5:47 pm
[...] 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. [...]
April 2nd, 2008 at 4:40 am
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
April 2nd, 2008 at 12:25 pm
pavan: Zenity tutorial here.
http://linux.byexamples.com/archives/259/a-complete-zenity-dialog-examples-1/
June 13th, 2008 at 12:52 pm
[...] [...]
January 4th, 2010 at 7:45 pm
This is example dialog in perl: pastebin.com/f6fe3c4fd ;)
May 28th, 2012 at 9:32 am
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.