On Click of a Button, the dialog box will open and user can select colour. On Submit or selection of the color the dialog box will close and the Hex, RGB and hsl values of the selected color will be printerd to the console.
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.dialogs.colorchooser import ColorChooserDialog
my_w = ttk.Window(themename="lumen")
my_w.geometry("300x200") # width and height
cd = ColorChooserDialog()
def my_show():
cd.show() # display the colour dialog or window
colors = cd.result # collect the user selection
print(colors.hex,colors.rgb,colors.hsl )
b1=ttk.Button(my_w,text='Select Colour',
bootstyle=SUCCESS,command=lambda:my_show())
b1.grid(row=0,column=0,padx=10,pady=20)
my_w.mainloop()
ColorChooserDialog to Select colour by user using ttkbootstrap
Updating background colour of the window
On click of the button, user can select and udpate the colour of the parent window.
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.dialogs.colorchooser import ColorChooserDialog
my_w = ttk.Window(themename="lumen")
my_w.geometry("300x200") # width and height
cd = ColorChooserDialog()
def my_show():
cd.show() # display the colour dialog or window
colors = cd.result # collect the user selection
my_w.configure(background=colors.hex) # Update window background
b1=ttk.Button(my_w,text='Select Colour',
bootstyle=SUCCESS,command=lambda:my_show())
b1.grid(row=0,column=0,padx=10,pady=20)
my_w.mainloop()
Updating Button colour based on user selection
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.dialogs.colorchooser import ColorChooserDialog
my_w = ttk.Window(themename="lumen")
my_w.geometry("400x200") # width and height
style = ttk.Style()
style.configure('TButton', background='green', foreground='white',
font=('Times', 20))
cd = ColorChooserDialog()
def my_show():
cd.show()
colors=cd.result
style.configure('TButton', background=colors.hex, foreground='white',
font=('Helvetica', 20,'underline'))
b1=ttk.Button(my_w,text='Select Colour',
style='custom.TButton',command=lambda:my_show())
b1.grid(row=0,column=0,padx=10,pady=20)
my_w.mainloop()
Updating colours of Button and Labels
Based on user selection one Label will have new background color and other Label will have new foreground colour.