Table of Contents
In this article, we will use zenity to create a form dialog. I think this is a very interesting feature in zenity. When creating the GUI, creating a form is indispensable. And with just a few lines of zenity code, you can create a form with basic functionality.
Create a form dialog
To create a form dialog, you use the --forms option in zeniy.
zenity --formsWhen you type the command above, a basic dialog will open. However, you will not be able to enter any data because the form is empty at this time.

In the next article, we will talk about the options of --forms. When using these options, you can create a complete form to use.
Forms options
The table below shows the options of the form in zenity.
| Option | Meaning |
--add-entry | Add a new entry in form dialog. You can add many entry as you want. |
--add-password | Add a new password entry in form dialog. The text you type in this entry will be hide. |
--add-calendar | Add a new calendar in form dialog. When you select a date in the form, it returns the date in the command window. |
--text | Set the dialog text. You can add a note to your form via this option. |
--separator | Set output separator character. Default is ‘|’, you should put it in parentheses. |
--forms-date-format | Set the format for the returned date. This option formats the results when you use –add-calendar. This option use strftime function, for example %A %d/%m/%y. |
The --forms-date-format option uses the strftime function, which you can read under the link I mentioned in a zenity calendar article.
In the example below, I will use all of the options above to create a form dialog.
zenity --forms --add-entry=Username --add-password=Password --add-calendar=Date --text="WriteBash.com Demo Form" --separator=';' --forms-date-format=%d/%m/%Y
When you enter the information, select the date on the calendar. A result line will return as the image below.

The stream of data returned in the image above, you can use it in your scripts.
Create a form dialog with bash script
Content script below is used in part from documents Zenity, you can copy the script below and use on your computer.
Read more: Make bash script run as a service in CentOS 7.
#!/bin/bash
# Script author: Danie Pham
# Script site: https://devopslite.com
# Script date: 26-01-2018
# Script use to create a form dialog by using Zenity
# Function create a form
f_create_form () {
# This content is reused from the Zenity document
zenity --forms --title="Add Friend" \
--text="Enter information about your friend." \
--separator="," \
--add-entry="First Name" \
--add-entry="Family Name" \
--add-entry="Email" \
--add-calendar="Birthday" >> addr.csv
case $? in
0) echo "Friend added." ;;
1) echo "No friend added." ;;
-1) echo "An unexpected error has occurred." ;;
esac
}
# Main function
f_main () {
f_create_form
}
f_main
exitConclusion
I personally think this is a powerful option of zenity. With just a few lines of code, you can create a form dialog. When combined with the bash script, you can make it a complete program.
(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).
An example using the last implementations –add-list, –list-values and –show-header
zenity –forms \
–text “Formulário com lista de duas colunas” \
–add-entry “Nome” –add-list=”Lista dupla” \
–column-values “Núm|Descritivo” \
–list-values=”1|Primeira Linha|2|Segunda Linha\
|3|Terceira linha|” –show-header