Zenity

From Wikipedia, the free encyclopedia
Jump to: navigation, search
Zenity
Gnome zenity infobox.png
Window, created with the following command:
$ zenity --info --text="This is an information box."
Original author(s) Sun Microsystems
Developer(s) Glynn Foster
Lucas Rocha
Stable release 3.2.2  (16 November 2011; 2 months ago (2011-11-16))[1] [±]
Preview release 3.3.4  (26 January 2012; 2 days ago (2012-01-26))[2] [±]
Development status Active
Operating system UNIX-like
License GNU General Public License
Website live.gnome.org/Zenity

Zenity is a cross-platform program that allows the execution of GTK+ dialog boxes in command-line and shell scripts.

Contents

[edit] Description

Like tools such as whiptail and dialog, zenity allows for easy creation of GUIs[3], though it has fewer features than more complex GUI creation tools.[4]

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.

Chris Tyler[5]

[edit] Cross-platform compatibility

At the moment Zenity is available for Linux, BSD and Windows.[6] GTK+, the library on which Zenity is based, is also available for MacOS.[7] 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 as these are available for several platforms.[8]

[edit] Cross-platform script example

Zenity-ubuntu-lucid.png
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!')


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

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

[edit] See also

[edit] References

[edit] External links


Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages