Jump to content

Zenity

From Alfawiki
Adapted from the English Wikipedia article Zenity, available under CC BY-SA 4.0Updated 9 August 20254 sources
Zenity
Company typeFree and open-source software
IndustrySoftware development
Area served
Cross-platform (Linux, BSD, Windows, Mac OS X)
ProductsGTK dialog boxes for command-line and shell scripts
Websitehelp.gnome.org/users/zenity/

Zenity is a free and open-source application designed to run GTK dialog boxes from within command-line environments and shell scripts, functioning across multiple operating systems.

Description

Zenity, comparable to utilities such as whiptail and dialog, simplifies the process of generating graphical user interfaces,[1] although it provides a more limited feature set relative to comprehensive GUI development tools.[2]

Cross-platform compatibility

By 2012, Zenity was compatible with Linux, BSD variants, and Windows platforms.[3] Users can also access Mac OS X versions through package managers like MacPorts and Homebrew.

As of 2018, Windows distributions include zenity-windows, derived from version 3.20.0, and winzenity, based on version 3.8.0 with static linking.

Zenity itself does not incorporate native scripting functions and relies on an external interpreter to operate. For scripts intended to run cross-platform with minimal adjustments, it is advisable to use interpreters broadly supported across systems—such as Python paired with the PyZenity module.[4]

Python example

<syntaxhighlight lang="python"> 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!")

</syntaxhighlight>

POSIX shell script example

<syntaxhighlight lang="bash">

  1. !/bin/sh

if zenity --question --text="Please press a button."; then

 zenity --info --text="You pressed Yes!"

else

 zenity --error --text="You pressed No!"

fi </syntaxhighlight>

Windows shell script example

<syntaxhighlight lang="dosbatch"> @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

</syntaxhighlight>

See also

External links

  1. ↑ Cite error: Invalid <ref> tag; no text was provided for refs named fsm-more-fun
  2. ↑ Cite error: Invalid <ref> tag; no text was provided for refs named lj-zenity-friendly
  3. ↑ Cite error: Invalid <ref> tag; no text was provided for refs named placella
  4. ↑ Cite error: Invalid <ref> tag; no text was provided for refs named brianramos