Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. from tkinter import *
  2. # import math - uncomment if required
  3. root = Tk()
  4. root.geometry("400x400+0+0")
  5.  
  6. #---------Backgroud of the main canvas-----
  7.  
  8. backgroundCanvas = Canvas(root,bg = '#c3fc5a', width = 400, height = 400)
  9. backgroundCanvas.pack()
  10.  
  11. #--------------------Variables---------------------
  12.  
  13. colour_support = ["red","green","blue"]
  14. rgb_conversion = [[255,0,0],[0,255,0],[0,0,255]]
  15. current_colour = [0,0,0]
  16.  
  17. #-----------------Main Functions-------------------
  18.  
  19. def dyn_Sliders():
  20. for x in range(len(colour_support)):
  21. #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()))')
  22. 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()))')
  23. exec(colour_support[x] + '_slider.place(x=50*x,y=50)')
  24. #exec(colour_support[x] +'_slider.configure(command=lambda x: refreshCol(str("'+colour_support[x]+'"),str('+colour_support[x]+'_slider.get())))')
  25.  
  26. #---------------Additional--Functions--------------
  27.  
  28. def refreshCol(selectedColour, valueChange):
  29. print(valueChange)
  30. current_colour[colour_support.index(selectedColour)] = int(valueChange)
  31. print(current_colour)
  32.  
  33. def printHex():
  34. 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)))
  35.  
  36. #--------The other widgets inside the canvas--------
  37.  
  38. dyn_Sliders()
  39. hexButton = Button(backgroundCanvas,text='Print hex value',command = printHex)
  40. hexButton.place(x=10,y=200)
  41.  
  42. #-------------------Start the GUI----------------------
  43.  
  44. root.title="Mansell's HOMEMADE RGB Sliders"
  45. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement