Zenity: Red Hat Enterprise Linux 8.4
Anudeep Nalla
Opensource Contributer | Platform Engineer | EX-NPCI | RHCA Level III | OpenShift | CEPH | CK{S,A,AD} | 3x Microsoft Certified | AWS CSA | Rancher | Nirmata | DevOps | Ansible | Jenkins | DevSecOps | Kyverno | Rook-Ceph
What is Zenity?
Zenity?is an open source and a cross-platform application which displays?GTK+ Dialog Boxes?in command-line and using shell scripts. It allows to ask and present information to/from shell in Graphical Boxes. The application lets you create Graphical dialog boxes in command-line and makes the interaction between user and shell very easy.
There are other alternatives,?but nothing compares to the simplicity of?Zenity, specially when you don’t need complex programming. Zenity, a tool you must have your hands on.
Zenity Features
1.???FOSS Software
2.???Cross Platform Application
3.???Allow GTK+ Dialog Box Execution
4.???Command Line Tool
5.???Support in Shell Scripting
Uses of Zenity
1.???Easy GUI Creation
2.???Less features than other complex Tools
3.???Enables shell scripts to interact with a GUI users
4.???Simple dialog creation is possible for graphical user interaction
Since?Zenity?is available for all known major platforms, and based on GTK+ library, Zenity program can be ported to/from another platform.
By using Zenity, we can create GUI boxes for the following:
Calendar
File selection
Forms
List
Notification icon
Message
Error
Information
Question
Warning
Password entry
Progress
Text entry
Text information
Scale
Color selection
The entry widget
The entry widget is useful when we need to ask the user for some text. Say for example we need to ask the user to enter its name; we can run the following command:
zenity --entry --title "Name request" --text "Please enter your name:"
领英推荐
File selection widget
The file selection widget let us display a nice graphical interface to let the user select one or more files. Just as we did in the previous examples, we can use a series of options to modify the behavior and appearance of the dialogue. One of the most important one is?--filename?which can be used to set the file/directory that will be selected by default.?
zenity --file-selection --multiple --filename "${HOME}/"
If we open the dialogue in?save mode, the user will be asked to provide the name of the file he wants to save. If the file exists and we provided the?--confirm-overwrite?option, he will be prompted to confirm he wants to overwrite it:
zenity --file-selection --save --confirm-overwrite --filename "${HOME}/"
The progress widget
#!/bin/bash
# Dummy script to demonstrate the zenity progress widget!
(
? echo 25
? echo "# Setting up..."
? sleep 2
? echo 30
? echo "# Reading files..."
? sleep 2
? echo 70
? echo "# Creating content..."
? sleep 1
? echo 100
? echo "# Done!"
) | zenity --title "Progress bar example" --progress --auto-killh
Info, warning and error widgets
The notification widget
zenity --info --width=400 --height=200 --text "This is a notification!"
The warning widget:
?zenity --warning --width=400 --height=200 --text "This is a warning!"
The error widget:
zenity --error --width=400 --height=200 --text "This is an error!"
The question widget
zenity --question --text "Are you sure you want to quit?" --no-wrap --ok-label "Yes" --cancel-label "No"
The color selection widget
zenity --color-selection --color red --show-palette
DevOps Engineer@Devtron Inc (?????????) || Kubernetes || Cloud || Trainer || ?? 7K+ Followers ?? || Job Support || AWS || Ansible || Docker || Jenkins || Terraform
3 年Great Anudeep Nalla
Senior DevOps Engineer at Crest Data Systems
3 年Nice Work !!
Combating FinCrime @ Airtel, Ex-Paytm
3 年great work :)