ZENITY COMMAND IN LINUX OS
The Following Article is to show You How Zenity Command can be used to allow the user to interact with device in GUI manner. Let’s Begin !!
✅ TOPICS COVERED ARE :-
🔹 UNDERSTANDING BASICS OF ZENITY.
🔹 THE CODE EXPLAINATION & HENCE EXPLORING MORE ZENITY FEATURES & OPTIONS.
🔰 What is Zenity ?
In Simple Words, Zenity is a CLI(Command Line Interface) which can be used in the Command Prompt Terminal to create Various Dialogue Boxes & Display them according to The Input Given by the USER.
In other Words, to make the interaction with Device much easy, This Graphical Tool is Used which Can also Result in Saving Time.
Let’s get this concept Clear with a practical Example.
🔹 In the Image Given Below, you can see that to display calendar I've Simply used Cal Keyword/Command.
🔹Now You can see I have used the Zenity command to display the same calendar in a Dialogue Box.
Syntax : zenity — calendar
🔹Let’s make it clear with one more example. Here I’ve used zenity information dialogue box to display the Month using date command alongside.
Syntax : zenity — info — title=date =text=$(date +%B)
Note : For now just look at how the zenity works, the syntax we will look in more depth as we’ll more Forward towards the Code.
🔰 CODE WORKING :
Here I’ve written a Simple Code to Show you The Dialogue Boxes That Appears when you install Any Software/Game,etc.
✅ STEP 1:
Code :
TERM=`dirname $0`/terms.txt
zenity — text-info — width=800 — height=800 \
— title=”License Agreement” \
— filename=$TERM \
— checkbox=”I read and accept the terms.”
So here first I have used zenity — text-info dialogue box to Add Terms & Condition Text and after Specifying which dialogue box to use, using the — height and — width function you can set the Dimensions of Dialogue Box.
— title=”<TEXT>” Syntax is used to set title name of dialogue box.
— filename=$TERM means, the Text You want to Add in the — text-info box, make sure that the text file is in same folder where the SCRIPT is located otherwise while execution, filename command won’t be able to read the file.
TERM=`dirname $0`/terms.txt , Here the text file name terms is assigned to the TERM where dirname is the directory name which is same as of script and in the filename=$TERM, the $ sign is taking term as a command that will locate the file and add it.
At last the — checkbox=<”TEXT”> syntax is used to add Checkbox which all together at the end will result in the Below Dialogue Box.
✅ STEP 2:
Code :
zenity — info — width=300 — height=300 — title=”SOFTWARE INSTALLATION” — text=”Select Location to Install The Software”
Here, Simply a zenity — Info “INFORMATION” box is used with the same syntax as above and — text to ask user to select location to install the Software which will result in
✅ STEP 3:
Code :
zenity — file-selection
Now We’ll Open — file-selection option which doesn’t open any dialogue box but the OS folders to select. Example given below
✅ STEP 3:
Code :
zenity — list — width=300 — height=300 — checklist — title “INSTALLAION PROCESS” — text “Select Where To create Shortcut Icon” — column “” — column “Select” False “START MENU” False DESKTOP — ok-label=Proceed
zenity — list — checklist command is used where a list will be displayed with the Option which can be Ticked & To Create there Option we use — column command in which FALSE means option is not Ticked & TRUE means option is ticked before Displaying with text to be written after each True & False.
Now This Results in
✅ STEP 4:
Code :
(
echo 25
echo “# EXTRACTING PACKAGES”
sleep 1
echo 40
echo “# CREATING SHORTCUTS”
sleep 1
echo 75
echo “#ASSIGNING FOLDERS”
sleep 1
echo 100
echo “# DONE”
) | zenity — title “INSTALLATION IN PROGRESS” — progress
echo normally in LINUX word as a Print Command which means it Prints whatever text, etc assigned to it. But in the Zenity — progress dialogue box the Progress is Shown like its Loading. Now to Control how Fast you want to process, using this syntax Example,
( echo 75
echo “#ASSIGNING FOLDERS”
sleep 1
) | zenity — title “INSTALLATION IN PROGRESS” — progress
the echo with integer value will be taken as at which point the progress bar should pause and echo with text will display the text itself at that point & sleep 1 means the bar will stop/pause for 1 second. Hence all together it will now result something like this
✅ STEP 5:
Code : zenity — info — width=300 — height=300 — title=”SETUP COMPLETE” — text=” PYTHON SUCCESSFULLY INSTALLED”
Noting New as we already discussed the Information Dialogue box.
✅ STEP 6:
Code :
zenity — question — width=300 — height=300 — title=”SETUP COMPLETE” — text=”DO YOU WANT TO LAUNCH PYTHON 3.0.6 “ — ok-label “Yes” — cancel-label “No”
Now as we successfully installed the Software, I will ask whether the Software should be launched or not using zenity — question dialogue box & the — ok-lable”Yes” — cancel-lable”No” means every Dialogue box by default have ok and Cancel Option which using Label keyword can be changed to Respective Text. Now we Have This.
✅ STEP 7:
Code :
ACCOUNT=$(zenity — forms — width=300 — title=”CREATE PYTHON3 ACCOUNT” \
— text=”Enter Your Information.” \
— add-entry=”Full Name” )
Now, We are asking user to enter His Name using — entry command where he will enter his name & we are storing it in ACCOUNT so that we can further use the name to display whenever required. Now we have..
✅ STEP 8:
Code :
zenity — info — width=300 — height=300 — title=”INSTALLATION DONE” — text=”ACCOUNT HAVE BEEN SUCCESSFULLY CREATED…..ENJOY CODING”
Again to Simply Display that the Account is Successfully Created
✅ STEP 9:
Code :
zenity — info — width=300 — height=300 — title=”PYTHON 3.0.6" — text=”WELCOME $ACCOUNT CLICK ON LAUNCH PYTHON “ — ok-label “Launch Python3”
python3
Here as You can See the $ACCOUNT means in step where we entered user’s name, the name will be displayed here. and the python3 command is just to launch python3 in LINUX Terminal.
✅ STEP 10 : PYTHON3 IS SUCCESSFULLY LAUNCHED.
🔰 AND AS A RESULT WE SUCCESSFULLY LOOKED & UNDERSTOOD HOW THE ZENITY DIALOGUE BOXES CAN BE USED TO CREATE A SIMPLE INSTALLATION PROCESS IN 10 EASY STEPS :)
https://www.linkedin.com/pulse/zenity-command-linuxos-swaroop-shinde