Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
old_color_prev.grid(row=0, column=0)
self.color_preview.grid(row=0, column=1)
# --- palette
palette = ttk.Frame(frame)
palette.grid(row=0, column=1, rowspan=2, sticky="ne")
for i, col in enumerate(PALETTE):
f = ttk.Frame(palette, borderwidth=1, relief="raised",
style="palette.TFrame")
l = tk.Label(f, background=col, width=2, height=1)
l.bind("<1>", self._palette_cmd)
f.bind("", lambda e: e.widget.configure(relief="raised"))
l.pack()
f.grid(row=i % 2, column=i // 2, padx=2, pady=2)
col_frame = ttk.Frame(self)
# --- hsv
hsv_frame = ttk.Frame(col_frame, relief="ridge", borderwidth=2)
hsv_frame.pack(pady=(0, 4), fill="x")
hsv_frame.columnconfigure(0, weight=1)
self.hue = LimitVar(0, 360, self)
self.saturation = LimitVar(0, 100, self)
self.value = LimitVar(0, 100, self)
# self.hue = tk.StringVar(self)
# self.saturation = tk.StringVar(self)
# self.value = tk.StringVar(self)
s_h = Spinbox(hsv_frame, from_=0, to=360, width=4, name='spinbox',
textvariable=self.hue, command=self._update_color_hsv)
s_s = Spinbox(hsv_frame, from_=0, to=100, width=4,
textvariable=self.saturation, name='spinbox',
command=self._update_color_hsv)
# --- palette
palette = ttk.Frame(frame)
palette.grid(row=0, column=1, rowspan=2, sticky="ne")
for i, col in enumerate(PALETTE):
f = ttk.Frame(palette, borderwidth=1, relief="raised",
style="palette.TFrame")
l = tk.Label(f, background=col, width=2, height=1)
l.bind("<1>", self._palette_cmd)
f.bind("", lambda e: e.widget.configure(relief="raised"))
l.pack()
f.grid(row=i % 2, column=i // 2, padx=2, pady=2)
col_frame = ttk.Frame(self)
# --- hsv
hsv_frame = ttk.Frame(col_frame, relief="ridge", borderwidth=2)
hsv_frame.pack(pady=(0, 4), fill="x")
hsv_frame.columnconfigure(0, weight=1)
self.hue = LimitVar(0, 360, self)
self.saturation = LimitVar(0, 100, self)
self.value = LimitVar(0, 100, self)
# self.hue = tk.StringVar(self)
# self.saturation = tk.StringVar(self)
# self.value = tk.StringVar(self)
s_h = Spinbox(hsv_frame, from_=0, to=360, width=4, name='spinbox',
textvariable=self.hue, command=self._update_color_hsv)
s_s = Spinbox(hsv_frame, from_=0, to=100, width=4,
textvariable=self.saturation, name='spinbox',
command=self._update_color_hsv)
s_v = Spinbox(hsv_frame, from_=0, to=100, width=4, name='spinbox',
textvariable=self.value, command=self._update_color_hsv)
self.color_preview = tk.Label(preview_frame, pady=0, padx=0,
image=self._im_color,
borderwidth=0, highlightthickness=0)
else:
old_color_prev = tk.Label(preview_frame, background=old_color[:7],
width=5, highlightthickness=0, height=2,
padx=0, pady=0)
self.color_preview = tk.Label(preview_frame, width=5, height=2,
pady=0, background=old_color[:7],
padx=0, highlightthickness=0)
old_color_prev.bind("<1>", self._reset_preview)
old_color_prev.grid(row=0, column=0)
self.color_preview.grid(row=0, column=1)
# --- palette
palette = ttk.Frame(frame)
palette.grid(row=0, column=1, rowspan=2, sticky="ne")
for i, col in enumerate(PALETTE):
f = ttk.Frame(palette, borderwidth=1, relief="raised",
style="palette.TFrame")
l = tk.Label(f, background=col, width=2, height=1)
l.bind("<1>", self._palette_cmd)
f.bind("", lambda e: e.widget.configure(relief="raised"))
l.pack()
f.grid(row=i % 2, column=i // 2, padx=2, pady=2)
col_frame = ttk.Frame(self)
# --- hsv
hsv_frame = ttk.Frame(col_frame, relief="ridge", borderwidth=2)
hsv_frame.pack(pady=(0, 4), fill="x")
hsv_frame.columnconfigure(0, weight=1)
self.hue = LimitVar(0, 360, self)
else:
old_color_prev = tk.Label(preview_frame, background=old_color[:7],
width=5, highlightthickness=0, height=2,
padx=0, pady=0)
self.color_preview = tk.Label(preview_frame, width=5, height=2,
pady=0, background=old_color[:7],
padx=0, highlightthickness=0)
old_color_prev.bind("<1>", self._reset_preview)
old_color_prev.grid(row=0, column=0)
self.color_preview.grid(row=0, column=1)
# --- palette
palette = ttk.Frame(frame)
palette.grid(row=0, column=1, rowspan=2, sticky="ne")
for i, col in enumerate(PALETTE):
f = ttk.Frame(palette, borderwidth=1, relief="raised",
style="palette.TFrame")
l = tk.Label(f, background=col, width=2, height=1)
l.bind("<1>", self._palette_cmd)
f.bind("", lambda e: e.widget.configure(relief="raised"))
l.pack()
f.grid(row=i % 2, column=i // 2, padx=2, pady=2)
col_frame = ttk.Frame(self)
# --- hsv
hsv_frame = ttk.Frame(col_frame, relief="ridge", borderwidth=2)
hsv_frame.pack(pady=(0, 4), fill="x")
hsv_frame.columnconfigure(0, weight=1)
self.hue = LimitVar(0, 360, self)
self.saturation = LimitVar(0, 100, self)
self.value = LimitVar(0, 100, self)
# self.hue = tk.StringVar(self)
def __init__(self, parent, **kwargs):
"""
Create a Spinbox.
The keyword arguments are the same as for a tk.Spinbox.
"""
self.style = ttk.Style(parent)
self.frame = ttk.Frame(parent, class_="ttkSpinbox",
relief=kwargs.get("relief", "sunken"),
borderwidth=1)
self.style.configure("%s.spinbox.TFrame" % self.frame,
background="white")
self.frame.configure(style="%s.spinbox.TFrame" % self.frame)
kwargs["relief"] = "flat"
kwargs["highlightthickness"] = 0
kwargs["selectbackground"] = self.style.lookup("TEntry",
"selectbackground",
("focus",))
kwargs["selectbackground"] = self.style.lookup("TEntry",
"selectbackground",
("focus",))
kwargs["selectforeground"] = self.style.lookup("TEntry",
"selectforeground",
("focus",))
self._old_alpha = 255
args = self._old_color + (255,)
old_color = rgb_to_hexa(*args)
else:
self._old_color = color[:3]
if alpha:
if len(color) < 4:
color += (255,)
self._old_alpha = 255
else:
self._old_alpha = color[3]
old_color = rgb_to_hexa(*color)
# --- GradientBar
hue = col2hue(*self._old_color)
bar = ttk.Frame(self, borderwidth=2, relief='groove')
self.bar = GradientBar(bar, hue=hue, width=200, highlightthickness=0)
self.bar.pack()
# --- ColorSquare
square = ttk.Frame(self, borderwidth=2, relief='groove')
self.square = ColorSquare(square, hue=hue, width=200, height=200,
color=rgb_to_hsv(*self._old_color),
highlightthickness=0)
self.square.pack()
frame = ttk.Frame(self)
frame.columnconfigure(1, weight=1)
frame.rowconfigure(1, weight=1)
# --- color preview: initial color and currently selected color side by side
preview_frame = ttk.Frame(frame, relief="groove", borderwidth=2)
if alpha:
if len(color) < 4:
color += (255,)
self._old_alpha = 255
else:
self._old_alpha = color[3]
old_color = rgb_to_hexa(*color)
# --- GradientBar
hue = col2hue(*self._old_color)
bar = ttk.Frame(self, borderwidth=2, relief='groove')
self.bar = GradientBar(bar, hue=hue, width=200, highlightthickness=0)
self.bar.pack()
# --- ColorSquare
square = ttk.Frame(self, borderwidth=2, relief='groove')
self.square = ColorSquare(square, hue=hue, width=200, height=200,
color=rgb_to_hsv(*self._old_color),
highlightthickness=0)
self.square.pack()
frame = ttk.Frame(self)
frame.columnconfigure(1, weight=1)
frame.rowconfigure(1, weight=1)
# --- color preview: initial color and currently selected color side by side
preview_frame = ttk.Frame(frame, relief="groove", borderwidth=2)
preview_frame.grid(row=0, column=0, sticky="nw", pady=2)
if alpha:
self._transparent_bg = create_checkered_image(42, 32)
transparent_bg_old = create_checkered_image(42, 32,
(100, 100, 100, 255),
old_color = rgb_to_hexa(*color)
# --- GradientBar
hue = col2hue(*self._old_color)
bar = ttk.Frame(self, borderwidth=2, relief='groove')
self.bar = GradientBar(bar, hue=hue, width=200, highlightthickness=0)
self.bar.pack()
# --- ColorSquare
square = ttk.Frame(self, borderwidth=2, relief='groove')
self.square = ColorSquare(square, hue=hue, width=200, height=200,
color=rgb_to_hsv(*self._old_color),
highlightthickness=0)
self.square.pack()
frame = ttk.Frame(self)
frame.columnconfigure(1, weight=1)
frame.rowconfigure(1, weight=1)
# --- color preview: initial color and currently selected color side by side
preview_frame = ttk.Frame(frame, relief="groove", borderwidth=2)
preview_frame.grid(row=0, column=0, sticky="nw", pady=2)
if alpha:
self._transparent_bg = create_checkered_image(42, 32)
transparent_bg_old = create_checkered_image(42, 32,
(100, 100, 100, 255),
(154, 154, 154, 255))
prev_old = overlay(transparent_bg_old, hexa_to_rgb(old_color))
prev = overlay(self._transparent_bg, hexa_to_rgb(old_color))
self._im_old_color = ImageTk.PhotoImage(prev_old, master=self)
self._im_color = ImageTk.PhotoImage(prev, master=self)
old_color_prev = tk.Label(preview_frame, padx=0, pady=0,
s_s.delete(0, 'end')
s_s.insert(0, s)
s_v.delete(0, 'end')
s_v.insert(0, v)
s_h.grid(row=0, column=1, sticky='w', padx=4, pady=4)
s_s.grid(row=1, column=1, sticky='w', padx=4, pady=4)
s_v.grid(row=2, column=1, sticky='w', padx=4, pady=4)
ttk.Label(hsv_frame, text=_('Hue')).grid(row=0, column=0, sticky='e',
padx=4, pady=4)
ttk.Label(hsv_frame, text=_('Saturation')).grid(row=1, column=0, sticky='e',
padx=4, pady=4)
ttk.Label(hsv_frame, text=_('Value')).grid(row=2, column=0, sticky='e',
padx=4, pady=4)
# --- rgb
rgb_frame = ttk.Frame(col_frame, relief="ridge", borderwidth=2)
rgb_frame.pack(pady=4, fill="x")
rgb_frame.columnconfigure(0, weight=1)
# self.red = tk.StringVar(self)
# self.green = tk.StringVar(self)
# self.blue = tk.StringVar(self)
self.red = LimitVar(0, 255, self)
self.green = LimitVar(0, 255, self)
self.blue = LimitVar(0, 255, self)
s_red = Spinbox(rgb_frame, from_=0, to=255, width=4, name='spinbox',
textvariable=self.red, command=self._update_color_rgb)
s_green = Spinbox(rgb_frame, from_=0, to=255, width=4, name='spinbox',
textvariable=self.green, command=self._update_color_rgb)
s_blue = Spinbox(rgb_frame, from_=0, to=255, width=4, name='spinbox',
textvariable=self.blue, command=self._update_color_rgb)
s_red.delete(0, 'end')