Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- # import math - uncomment if required
- root = Tk()
- root.geometry("400x400+0+0")
- #---------Backgroud of the main canvas-----
- backgroundCanvas = Canvas(root,bg = '#c3fc5a', width = 400, height = 400)
- backgroundCanvas.pack()
- #--------------------Variables---------------------
- colour_support = ["red","green","blue"]
- rgb_conversion = [[255,0,0],[0,255,0],[0,0,255]]
- current_colour = [0,0,0]
- #-----------------Main Functions-------------------
- def dyn_Sliders():
- for x in range(len(colour_support)):
- #exec('global colour_support[x]_slider; colour_support[x]+_slider = Scale(backgroundCanvas, from_=0, to=255,command = lambda x: refreshCol(str("colour_support[x]"),colour_support[x]_slider.get()))')
- exec('global '+colour_support[x]+'_slider; '+colour_support[x]+'_slider = Scale(backgroundCanvas, from_ = 0, to = 255,command = lambda x: refreshCol("'+str(colour_support[x])+'", '+colour_support[x]+'_slider.get()))')
- exec(colour_support[x] + '_slider.place(x=50*x,y=50)')
- #exec(colour_support[x] +'_slider.configure(command=lambda x: refreshCol(str("'+colour_support[x]+'"),str('+colour_support[x]+'_slider.get())))')
- #---------------Additional--Functions--------------
- def refreshCol(selectedColour, valueChange):
- print(valueChange)
- current_colour[colour_support.index(selectedColour)] = int(valueChange)
- print(current_colour)
- def printHex():
- print('#'+(str(hex(current_colour[0]).split('x')[-1].upper()).zfill(2))+(str(hex(current_colour[1]).split('x')[-1].upper()).zfill(2))+(str(hex(current_colour[2]).split('x')[-1].upper()).zfill(2)))
- #--------The other widgets inside the canvas--------
- dyn_Sliders()
- hexButton = Button(backgroundCanvas,text='Print hex value',command = printHex)
- hexButton.place(x=10,y=200)
- #-------------------Start the GUI----------------------
- root.title="Mansell's HOMEMADE RGB Sliders"
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement