Linux Dialog Box Commands


Dialog Box using Whiptail


Create Message Box

A dialog box which shows a simple message with “OK” and “Cancel” buttons
Syntax-
whiptail --title “Enter here title” --msgbox “Enter Message” <height> <width>

Code For Message Box
whiptail --title “Message” --msgbox “Are you having fun ?” 10 50





Create an Input Box

A dialog box which creates a textfield where user can input information
Syntax-
whiptail --title “Enter title here” --inputbox “Enter input” <height> <width>

Code For Input Box
X=$(whiptail --title "Feedback Form" --inputbox "How was the food that you ordered ?" 10 50 Excellent 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]
then
echo "Thank You" $X
else
echo "You cancelled the form"
fi





Create a Password Box

Syntax-
Whiptail --title “Enter title here” --passwordbox “Enter text” <height> <width>


Code For Password Box
X=$(whiptail --title "Private Work" --passwordbox "Enter You password" 10 50 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]
then
whiptail --title "Private work" --msgbox "Your password is $X" 10 50
else
whiptail --title "Private Work" --msgbox "See you soon" 10 50
fi





Create a Guage Bar or Progress Bar

A dialog box which shows a progress bar reading from initial value to final value (0 to 100) and displays in form of animation.
Syntax-

whiptail --guage <height> <width> <initialization>


Code For Progress Bar
{
for ((i=0; i<=100; i++ ))
do
sleep 1
echo $i
done
} | whiptail --gauge "Installing Grand Theft Auto V" 6 60 0






Create a CheckList

A dialog box which allows user for multiple selection from a range of options

Syntax-
whiptail --title “Enter title” --checklist "Text for list” <height> <width> <list height> /<tag> <item> <status> /


Code For Checklist
O=$(whiptail --title "Checklist" --checklist "Choose from these" 15 60 4 \
"1" "GTA 4" ON \
"2" "GTA 5" ON \
"3" "Just Cause 2" OFF \
"4" "MineCraft" OFF 3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]
then
whiptail --title "Message" --msgbox "You Selected $O" 10 50
whiptail --title "Thankyou" --msgbox "Thank You" 10 50
else
whiptail --title "Thankyou" --msgbox "See You soon" 10 50
fi






Create a Menu Box

A dialog box that has multiple options where user can scroll and select his desired choice and send the data as per he selected

Syntax-
whiptail --title "Title Here” --menu "text for display" <height> <width> <menu height> \<tag> <item> \  

Code For Menu

O=$(whiptail --title "Choose any one" --menu "Choose from these" 15 60 4 \
"1" "GTA 4v" \
"2" "GTA 5" \
"3" "Just Cause 2" \
"4" "MineCraft" 3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]
then
whiptail --title "Menu" --msgbox "You Selected $O" 10 50
whiptail --title "Thankyou" --msgbox "Thank You" 10 50
else
whiptail --title "Thankyou" --msgbox "See You soon" 10 50
fi



Create YesNo Box

A dialog box which shows a simple message with “OK” and “Cancel” buttons
Syntax-
whiptail --title “Enter here title” --yesno “Enter Message” <height> <width>

Code For YesNo Box
whiptail --title “YesNo” --yesno “Are you having fun ?” 10 50

Change button text

A dialog box which shows a simple message with “OK” and “Cancel” buttons
Syntax-
whiptail --title “Enter here title” --msgbox “Enter Message” --yes-button "text" <height> <width>
or

whiptail --title “Enter here title” --msgbox “Enter Message” --no-button "text" <height> <width>

UPDATE - A minor project based on whiptail

Code - 

⁠⁠⁠if (whiptail --title "Welcome" --yesno "Welcome\n Whether you want Veg food or Non Veg Food ?" --yes-button "Veg" --no-button "Non-Veg" 10 60)then
while :
do
X=$(whiptail --title "Vegetarian Food List" --checklist "Select the food items you want" 30 60 5 \
"Matar Paneer" "1" OFF \
"Paneer Butter Masala" "2" OFF \
"Shaahi Paneer" "3" OFF \
"Dal Makhni" "4" OFF \
"Bhindi Fry" "5" OFF 3>&1 1>&2 2>&3)
if ( -z "$X" )then
continue
else
break
fi
done 
if (whiptail --title "Your Order" --yesno "You selected $X \n Click to confiirm" --yes-button "Confirm" 10 60)then
{
for ((i=0;i<=100;i++))
do
sleep 0
echo $i
done
} | whiptail --gauge "Booking Your Order" 6 60 0
whiptail --title "Thankyou" --msgbox "Your Items have been booked !!" 10 60
else
whiptail --title "Thankyou" --msgbox "Thankyou for wasting our time you moron" 20 60
fi
else
Y=$(whiptail --title "Non-Vegetarian Food List" --checklist "Select the food items you want" 30 60 5 \
"Chicken Fry" "1" OFF \
"Mutton Gravy" "2" OFF \
"Chicken Boneless" "3" OFF \
"Chicken Alive" "4" OFF \
"Grind Chicken" "5" OFF 3>&1 1>&2 2>&3)
if (whiptail --title "You Order" --yesno "You selected $Y \n Click to confirm" --yes-button "Confirm" 10 60)then
{
for ((i=0;i<=100;i++))
do
sleep 0
echo $i
done
} | whiptail --gauge "Booking Your Order" 6 60 0
whiptail --title "Thankyou" --msgbox "You items have been booked !!" 10 60
else
whiptail --title "Thankyou" --msgbox "Thnkyou for wasting our time you moron" 20 60
fi 

fi

Here is the output



Comments

Popular posts from this blog

SPI Working with Verilog Code

Verilog Code for I2C Protocol

SR Flip Flop Verilog Code