﻿from tkinter import *

def couleur():
    R=scaleR.get()
    V=scaleV.get()
    B=scaleB.get()
    print(R,V,B)
    Rh,Rv,Rb=hex(R),hex(V),hex(B)
    print(Rh,Rv,Rb)
    if len(hex(R))==3:
        Rh=Rh[0:2]+"0"+Rh[2]
    if len(hex(V))==3:
        Rv=Rv[0:2]+"0"+Rv[2]
    if len(hex(B))==3:
         Rb=Rb[0:2]+"0"+Rb[2]

    newfond=("#"+Rh[2:4]+Rv[2:4]+Rb[2:4])
    fondR=("#"+Rh[2:4]+"0000")
    fondV=("#00"+Rv[2:4]+"00")
    fondB=("#0000"+Rb[2:4])
    print(newfond)
    print(Rh,Rv,Rb)
    canvas.config(background=newfond)
    canvasR.config(background=fondR)
    canvasV.config(background=fondV)
    canvasB.config(background=fondB)


root=Tk()
root.geometry('500x300')
root.title('Association des trois couleurs R, V, B')

valueR = IntVar(root)
scaleR = Scale(root, from_=0, to=255, showvalue=True, label='valeur de rouge',length=180,resolution=1,variable=valueR, tickinterval=100, orient='h')

valueV = IntVar(root)
scaleV = Scale(root, from_=0, to=255, showvalue=True, label='valeur de vert',length=180,resolution=1,variable=valueV, tickinterval=100, orient='h')

valueB = IntVar(root)
scaleB = Scale(root, from_=0, to=255, showvalue=True, label='valeur de bleu',length=180,resolution=1,variable=valueB, tickinterval=100, orient='h')

bout=Button(root,text="Afficher la couleur",command=couleur)
texte1=Label(root,text="En mélangeant les trois teintes suivantes")
texte2=Label(root,text="On obtient la couleur suivante")

fond="white"
canvasR=Canvas(root,height=40, width=40,background=fond)
canvasV=Canvas(root,height=40, width=40,background=fond)
canvasB=Canvas(root,height=40, width=40,background=fond)
canvas=Canvas(root,height=100, width=100,background=fond)

scaleR.place(x=10,y=10)
scaleV.place(x=10,y=110)
scaleB.place(x=10,y=210)

bout.place(x=260,y=10)
canvasR.place(x=200,y=80)
canvasV.place(x=300,y=80)
canvasB.place(x=400,y=80)
canvas.place(x=270,y=180)
texte1.place(x=210,y=40)
texte2.place(x=230,y=130)



root.mainloop()