Zenity create a form dialog

Share this post to your friends !

This entry is part 8 of 13 in the series GUI for bash script using Zenity

WriteBash - 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 --forms

When 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.

zenity-create-a-form-dialog-01 Zenity create a form dialog
Create a form dialog

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.

Zenity form options
--add-entryAdd a new entry in form dialog. You can add many entry as you want.
--add-passwordAdd a new password entry in form dialog. The text you type in this entry will be hide.
--add-calendarAdd a new calendar in form dialog. When you select a date in the form, it returns the date in the command window.
--textSet the dialog text. You can add a note to your form via this option.
--separatorSet output separator character. Default is ‘|’, you should put it in parentheses.
--forms-date-formatSet 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
zenity-create-a-form-dialog-02 Zenity create a form dialog
Create a form dialog with full options

When you enter the information, select the date on the calendar. A result line will return as the image below.

zenity-create-a-form-dialog-03 Zenity create a form dialog
The values return

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 moreMake bash script run as a service in CentOS 7.

# Script author: Danie Pham
# Script site: https://www.writebash.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." ;;

# Main function
f_main () {



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.

Continue reading the series«« Previous part: Zenity create a progress dialogNext part: Zenity create a scale dialog »»
If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.

Share this post to your friends !
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

single post bottom banner
«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.