Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_rgb_sliders.py
- from tkinter import *
- def on_drag(e):
- color_hex = f'#{r.get():02X}{g.get():02X}{b.get():02X}'
- tv_color.set(color_hex)
- lbl_color["bg"] = color_hex
- lbl2_color["bg"] = color_hex
- root = Tk()
- root.option_add("*Font", "consolas 20")
- tv_color = StringVar()
- Label(root, text="red", fg="red").grid(row=0, column=0, sticky="sw")
- Label(root, text="green", fg="green").grid(row=1, column=0, sticky="sw")
- Label(root, text="blue", fg="blue").grid(row=2, column=0, sticky="sw")
- r = Scale(root, from_=0, to=255, orient=HORIZONTAL, length=200, width=30, fg="red")
- g = Scale(root, from_=0, to=255, orient=HORIZONTAL, length=200, width=30, fg="green")
- b = Scale(root, from_=0, to=255, orient=HORIZONTAL, length=200, width=30, fg="blue")
- r.grid(row=0, column=1)
- g.grid(row=1, column=1)
- b.grid(row=2, column=1)
- r.set(128)
- g.set(128)
- b.set(128)
- r.bind('<B1-Motion>', on_drag)
- r.bind('<Button-1>', on_drag)
- g.bind('<B1-Motion>', on_drag)
- g.bind('<Button-1>', on_drag)
- b.bind('<B1-Motion>', on_drag)
- b.bind('<Button-1>', on_drag)
- lbl_color = Label(root, textvariable=tv_color)
- lbl_color.grid(row=3, columnspan=2, sticky="news")
- lbl2_color = Label(root, textvariable=tv_color, fg='white')
- lbl2_color.grid(row=4, columnspan=2, sticky="news")
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement