Advertisement
here2share

# Tk_rgb_sliders.py

Nov 17th, 2022 (edited)
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. # Tk_rgb_sliders.py
  2.  
  3. from tkinter import *
  4.  
  5. def on_drag(e):
  6.     color_hex = f'#{r.get():02X}{g.get():02X}{b.get():02X}'
  7.     tv_color.set(color_hex)
  8.     lbl_color["bg"] = color_hex
  9.     lbl2_color["bg"] = color_hex
  10.  
  11. root = Tk()
  12. root.option_add("*Font", "consolas 20")
  13. tv_color = StringVar()
  14. Label(root, text="red", fg="red").grid(row=0, column=0, sticky="sw")
  15. Label(root, text="green", fg="green").grid(row=1, column=0, sticky="sw")
  16. Label(root, text="blue", fg="blue").grid(row=2, column=0, sticky="sw")
  17. r = Scale(root, from_=0, to=255, orient=HORIZONTAL, length=200, width=30, fg="red")
  18. g = Scale(root, from_=0, to=255, orient=HORIZONTAL, length=200, width=30, fg="green")
  19. b = Scale(root, from_=0, to=255, orient=HORIZONTAL, length=200, width=30, fg="blue")
  20. r.grid(row=0, column=1)
  21. g.grid(row=1, column=1)
  22. b.grid(row=2, column=1)
  23. r.set(128)
  24. g.set(128)
  25. b.set(128)
  26. r.bind('<B1-Motion>', on_drag)
  27. r.bind('<Button-1>', on_drag)
  28. g.bind('<B1-Motion>', on_drag)
  29. g.bind('<Button-1>', on_drag)
  30. b.bind('<B1-Motion>', on_drag)
  31. b.bind('<Button-1>', on_drag)
  32. lbl_color = Label(root, textvariable=tv_color)
  33. lbl_color.grid(row=3, columnspan=2, sticky="news")
  34. lbl2_color = Label(root, textvariable=tv_color, fg='white')
  35. lbl2_color.grid(row=4, columnspan=2, sticky="news")
  36. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement