Zenity create color selection dialog

by Daniel Pham
Published: Updated:
This entry is part 4 of 13 in the series GUI for bash script using Zenity

Zenity supports a pretty interesting command that lets you create a color picker box. If you have ever worked with css then this is a useful tool for you. Zenity create color selection dialog that helps you choose color and returns you the hex code of that color.

Code create color selection dialog

This statement is very simple and the options are not many, you totally just write a few command line is already a color selection tool extremely useful for your work.

The command is:

zenity --color-selection

The above command uses the --color-selection option, besides, it includes the following options. You just type command below to show all options:

zenity --help-color-selection
--color-selectionDisplay color selection dialog. This is the main option that you have to use when you want to create a color selection box.
--color=VALUESet the initial color.(ex: #FFFFFF)
--show-palette Show the palette
Zenity create color selection dialog
Display other options of color-selection

Script create color selection dialog

The zenity documentation also provides quite a bit of detail on how to use the script to create a color picker. The point is that you can write it as a function or a small program in your big application.

The code below:

# Script by: Danie Pham
# Script site: https://devopslite.com
# Script date: 05-01-2018
# Script ver: 1.0
# Script use to create a color selection dialog. You can import file or funtion to your another script as a child program.

# Function create dialog
f_create_dialog () {
    # Define a variable to get the result
    COLOR=`zenity --color-selection --show-palette`

    # Use 'case' command to display result
    case $? in
        0)  echo "You selected: $COLOR";;
        1)  echo "No color selected.";;
        -1) echo "An unexpected error has occurred.";;

# Function main
main () {


After you create script, copy code above, you have to grant permission to the script and then execute script:

chmod +x create-dialog.sh

A color selection box will display like an image below.

Read moreZenity create a notification icon

Zenity create color selection dialog
Script create color-selection

After you select a color, the color picker will turn off and return the color code for you on the terminal screen. For old versions (ex: 3.8.0) zenity will return you hex code like this #ffff00000000, and with new version (ex: 3.18 and later), zenity will return you rgb code like this rgb(211,215,207).


Actually zenity is a very useful tool for those who are using bash because when you combine those two you can create very useful tools for your work.

(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).

0 0 votes
Article Rating
Series Navigation«« Previous part: Zenity create a notification iconNext part: Zenity create a password entry dialog »»

You may also like

Notify of
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 DevOpsLite.com – All rights reserved.

Please write sources “DevOpsLite.com” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.