Table of Contents
This article will guide you through create a text entry dialog. This dialog is quite simple, the number of support options of the command is not much so this will be short article and quick guide.
Create a text entry dialog
To create a text entry box, use the --entry option in zenity. The default dialog box will display as the image below.
zenity --entry
The table below show support options for --entry:
| Option | Meaning |
--text=text | Set the text is displayed in the text entry dialog. In the image above, it will replace text “Add a new entry”. |
--entry-text=text | Set the text is displayed in the entry field of the text entry dialog. Default the entry field is empty. |
--hide-text | Hide the text of the entry field. You can see image below. |
zenity --entry --title="WriteBash.com" --text="Demo text for dialog" --hide-text
You can try using the --entry-text option to see how it works. Text content as you enter the entry field will returned to the command window. Note that the text entry dialog box can only create a single text field.
Bash script create a text entry dialog
Here is the script to create a text entry dialog, the content of the script is quite simple. You just copy it to your computer or your program is okay.
Read more: Create a form dialog.
#!/bin/bash
# Script author: Danie Pham
# Script site: https://devopslite.com
# Script date: 30-01-2018
# Script use to create a text dialog by using Zenity
# Function create a scale dialog
f_create_entry () {
if zenity --entry \
--title="WriteBash.com Text Entry Dialog" \
--text="Enter your demo text here:" \
--entry-text "Demo text"
then echo $?
else echo "No text entered"
fi
}
# Main function
f_main () {
f_create_entry
}
f_main
exitConclusion
This article gives you a quick tutorial on how to create a text entry dialog, which is very simple but will be useful in some cases. Use your imagination to use it to try new things.
(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).