RGB Colour Sliders


RGB scale to get Colour code

Red Green Blue colour slider by using Tkinter scale to update background colour of buttons

Reading value of Scale

By using get() method we can read the value of the scale.
sc1.get()

Updating value on change of scale

We used command option to trigger a common function my_upd(v)
sc2 = tk.Scale(my_w, from_=0, to=255,bg='green', orient='horizontal',
    length=250,command=my_upd)

Getting Hex value from RGB

color_c='#%02x%02x%02x' % (sc1.get(), sc2.get(), sc3.get())

Updating font and background colour of button

By using config() method of button we can update the background colour ( bg ) and text options.
def my_upd(v):
    color_c='#%02x%02x%02x' % (sc1.get(), sc2.get(), sc3.get())
    b1.config(bg=color_c)  # Updating background colour of button
    b1.config(text=color_c)# Updating text of the button   
Full code is here
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("410x200") 

def my_upd(v):
    color_c='#%02x%02x%02x' % (sc1.get(), sc2.get(), sc3.get())
    b1.config(bg=color_c)  # Updating background colour of button
    b1.config(text=color_c)# Updating text of the button   

font1=('Time',18,'normal')    

sc1 = tk.Scale(my_w, from_=0, to=255,bg='red', orient='horizontal',
    length=250,command=my_upd)
sc1.grid(row=0,column=0,padx=5,pady=10) 

sc2 = tk.Scale(my_w, from_=0, to=255,bg='green', orient='horizontal',
    length=250,command=my_upd)
sc2.grid(row=1,column=0,pady=10) 

sc3 = tk.Scale(my_w, from_=0, to=255,bg='blue', orient='horizontal',
    length=250,command=my_upd)
sc3.grid(row=2,column=0,pady=10) 

b1=tk.Button(my_w,text='My colour',font=font1,width=8)
b1.grid(row=1,column=1,padx=7)
my_w.mainloop()
Python Tkinter Projects
Tkinter Scale Text Entry How to Validate user entered data
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



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