Knowpapa.com - a developer's blog

Tkinter Color Chooser Dialog Simple Demo

Here’s a quick demo of Color Chooser Dialog from Tkinter.

Python 2.x Version

from Tkinter import *
from tkColorChooser import askcolor              
def getColor():
    color = askcolor() 
    print color
Button(text='Select Color', command=getColor).pack()
mainloop()

Python 3.x Version

from tkinter import *
from tkinter.colorchooser import *
def getColor():
    color = askcolor() 
    print color
Button(text='Select Color', command=getColor).pack()
mainloop()

The print color command prints a tuple of the form:

((99, 222, 170), ‘#63deaa’),

where the first item of the tuple gives the RGB values of the selected color, while the second item of the tuple gives the hexadecimal color code for the selected color.

Here’s a snapshot of the resulting color chooser:
TK Color Chooser