Python tkinter Colorchooser

Colorchooser to select color in Tkinter

We can access the native colour picker dialog by using Tkinter colorchooser module.
Background colour using colorchooser
Using askcolor we can get the user selected colour as Hex code and also the R G B values.
c_code = colorchooser.askcolor()
On click of a button the native colour picker will be displayed, On selection of colour by user we can print the selected colour code.

Tkinter supported colors list

Tkinter colorchooser to use native colour picker module and assign selected colors to the widget
import tkinter as tk
from tkinter import colorchooser
def collect_color():
    c_code = colorchooser.askcolor()
    #my_w.config(background=c_code[1]) # change the background color of window
    print(c_code)
 
my_w = tk.Tk()
my_w.geometry("410x250")  # Size of the window 
b1=tk.Button(my_w,text='Select Background',command=lambda:collect_color())
b1.grid(row=1,column=1,padx=20,pady=20)
my_w.mainloop()  # Keep the window open
Changing the background colour of the window ( Un-comment the line above )
my_w.config(background=c_code[1])

Selecting background colour for buttons

Multiple buttons & colorchooser

We can display more Buttons and onClick of the button the colour picker dialog will open. User can select the colour and the button will use the selected colour as background colour.
import tkinter as tk
from tkinter import colorchooser
def collect_color(k):
    c_code = colorchooser.askcolor(title ="Select color")
    buttons[k].config(bg=c_code[1])
     
my_w = tk.Tk()
my_w.geometry("410x250")  # Size of the window 

n=20 # number of buttons
i=2 # row 
j=0 # column 
buttons = []
for k in range(n):
    e = tk.Button(my_w, text=k,height=2,width=10,
		command=lambda k=k: collect_color(k)) 
    e.grid(row=i, column=j,padx=1,pady=1)
    buttons.append(e)
    j=j+1
    if(j%5==0):
        i=i+1
        j=0
my_w.mainloop()  # Keep the window open

Using Tkinter ColorChooser for Color Selection in Python GUIs #tkinter #pythonGUI #colorChooser


Image Resizing image using PIL Upload and display image file
Colour selection dialog box using Ttkbootstrap

Author Image
Subhendu Mohapatra

AUTHOR

🎥 Join me live on YouTube

Passionate about coding and teaching, I love sharing practical programming tutorials on PHP, Python, JavaScript, SQL, and web development. With years of experience, my goal is to make learning simple, engaging, and project-oriented. Whether you're a beginner or an experienced developer, I believe learning by doing is the best way to master coding. Let's explore the world of programming together!

LinkedIn X (Twitter)
Subscribe to our YouTube Channel here



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer