Zenity
![]() | |
Original author(s) | Sun Microsystems |
---|---|
Developer(s) | Glynn Foster Lucas Rocha |
Repository | |
Operating system | Linux, Windows |
License | GNU General Public License |
Website | http://live.gnome.org/Zenity |
Zenity is a cross-platform program that allows the execution of GTK+ dialog boxes in command-line and shell scripts.
Like tools such as whiptail and dialog, zenity allows for easy creation of GUIs[1], though it has fewer features than more complex GUI creation tools [2]: "Other scripting languages such as Perl and Python can be used to construct full-scale GUI applications, but the zenity program enables a shell script to interact with a GUI user.... [The] user interface is not as refined as one that could be provided by a full-featured GUI application, but it is perfectly suitable for simple interactions." [3]
Example
zenity --info --text="This is an information box."
Cross-platform compatibility
At the moment Zenity is available for both Linux, FreeBSD and Windows[4]. GTK+, the library on which Zenity is based, is also available for MacOS[5]. It therefore should be possible to port Zenity also to this platform.
Zenity does not possess any built-in scripting capabilities and it must therefore rely on an interpreter for processing. If it is desired to create a script that runs on more than any one platform, without heavily modifying it, it will be best to use the same interpreter. One such option is Python in combination with PyZenity[6] as these are available for several platforms.
Cross-platform script example
from PyZenity import InfoMessage
from PyZenity import Question
from PyZenity import ErrorMessage
choice=Question('Please press a button.')
if choice:
InfoMessage('You pressed Yes!')
else:
ErrorMessage('You pressed No!')
Linux Bash shell script example
#!/bin/bash
if zenity --question --text="Please press a button."; then
zenity --info --text="You pressed Yes\!"
else
zenity --error --text="You pressed No\!"
fi
Windows example
@echo off
zenity --question --ok-label="Yes" --cancel-label="No" --text="Please press a button."
if %ERRORLEVEL% == 1 goto error
zenity --info --text="You pressed Yes!"
goto end
:error
zenity --error --text="You pressed No!"
:end
See also
References
- ^ More fun with Zenity: shell script/GUI interactivity
- ^ http://www.linuxjournal.com/content/make-your-scripts-user-friendly-zenity
- ^ Tyler, Chris (2006). "Chapter 4. Basic System Management". Fedora Linux. O'Reilly Media, Inc. pp. 258–259. ISBN 978-0-596-52682-5.
- ^ http://www.placella.com/software/zenity/
- ^ http://gtk-osx.sourceforge.net/
- ^ http://www.brianramos.com/?page_id=110
External links
- http://live.gnome.org/Zenity
- http://code.google.com/p/yad/ - yad (fork of Zenity)