RGB Colour Sliders


Tkinter Projects in Tkinter

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 Text Tkinter Entry How to Validate user entered data

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    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 FORUM . Contact us
    ©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer