How to use the ttkwidgets.color.functions.tk function in ttkwidgets

To help you get started, we’ve selected a few ttkwidgets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TkinterEP / ttkwidgets / ttkwidgets / color / alphabar.py View on Github external
:type height: int
        :param width: width of the widget in pixels
        :type width: int
        :param kwargs: options to be passed on to the :class:`tk.Canvas` initializer
        """
        tk.Canvas.__init__(self, parent, width=width, height=height, **kwargs)
        self.gradient = tk.PhotoImage(master=self, width=width, height=height)

        self._variable = variable
        if variable is not None:
            try:
                alpha = int(variable.get())
            except Exception:
                pass
        else:
            self._variable = tk.IntVar(self)
        if alpha > 255:
            alpha = 255
        elif alpha < 0:
            alpha = 0
        self._variable.set(alpha)
        try:
            self._variable.trace_add("write", self._update_alpha)
        except Exception:
            self._variable.trace("w", self._update_alpha)

        self.bind('', lambda e: self._draw_gradient(alpha, color))
        self.bind('', self._on_click)
        self.bind('', self._on_move)
github TkinterEP / ttkwidgets / ttkwidgets / color / alphabar.py View on Github external
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see .

Alpha channel gradient bar
"""


from PIL import Image, ImageTk
from .functions import tk, round2, rgb_to_hsv
from .functions import create_checkered_image


class AlphaBar(tk.Canvas):
    """Bar to select alpha value."""

    def __init__(self, parent, alpha=255, color=(255, 0, 0), height=11,
                 width=256, variable=None, **kwargs):
        """
        Create a bar to select the alpha value.

        :param parent: parent widget
        :type parent: widget
        :param alpha: initially selected alpha value (between 0 and 255)
        :type alpha: int
        :param color: gradient color in RGB format
        :type color: tuple[int]
        :param variable: variable linked to the alpha value
        :type variable: IntVar
        :param height: height of the widget in pixels
github TkinterEP / ttkwidgets / ttkwidgets / color / colorpicker.py View on Github external
(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,
                                      image=self._im_old_color,
                                      borderwidth=0, highlightthickness=0)
            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()
github TkinterEP / ttkwidgets / ttkwidgets / color / gradientbar.py View on Github external
tkcolorpicker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see .

HSV gradient bar
"""


from .functions import tk, round2, rgb_to_hexa, hue2col


class GradientBar(tk.Canvas):
    """HSV gradient colorbar with selection cursor."""

    def __init__(self, parent, hue=0, height=11, width=256, variable=None,
                 **kwargs):
        """
        Create a GradientBar.

        Keyword arguments:
            * parent: parent window
            * hue: initially selected hue value
            * variable: IntVar linked to the alpha value
            * height, width, and any keyword argument accepted by a tkinter Canvas
        """
        tk.Canvas.__init__(self, parent, width=width, height=height, **kwargs)

        self._variable = variable
github TkinterEP / ttkwidgets / ttkwidgets / color / gradientbar.py View on Github external
def __init__(self, parent, hue=0, height=11, width=256, variable=None,
                 **kwargs):
        """
        Create a GradientBar.

        Keyword arguments:
            * parent: parent window
            * hue: initially selected hue value
            * variable: IntVar linked to the alpha value
            * height, width, and any keyword argument accepted by a tkinter Canvas
        """
        tk.Canvas.__init__(self, parent, width=width, height=height, **kwargs)

        self._variable = variable
        if variable is not None:
            try:
                hue = int(variable.get())
            except Exception:
                pass
        else:
            self._variable = tk.IntVar(self)
        if hue > 360:
            hue = 360
        elif hue < 0:
            hue = 0
        self._variable.set(hue)
        try:
            self._variable.trace_add("write", self._update_hue)
github TkinterEP / ttkwidgets / ttkwidgets / color / limitvar.py View on Github external
tkcolorpicker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see .

Limited StringVar
"""


from .functions import tk


class LimitVar(tk.StringVar):
    def __init__(self, from_, to, master=None, value=None, name=None):
        tk.StringVar.__init__(self, master, value, name)
        try:
            self._from = int(from_)
            self._to = int(to)
        except ValueError:
            raise ValueError("from_ and to should be integers.")
        if self._from >= self._to:
            raise ValueError("from_ should be smaller than to.")
        # ensure that the initial value is valid
        val = self.get()
        self.set(val)

    def get(self):
        """
        Convert the content to int between the limits of the variable.
github TkinterEP / ttkwidgets / ttkwidgets / color / colorpicker.py View on Github external
"Hue": "Teinte", "Saturation": "Saturation", "Value": "Valeur",
      "Cancel": "Annuler", "Color Chooser": "Sélecteur de couleur",
      "Alpha": "Alpha"}

if getdefaultlocale()[0][:2] == 'fr':
    TR = FR
else:
    TR = EN


def _(text):
    """Translate text."""
    return TR.get(text, text)


class ColorPicker(tk.Toplevel):
    """Color picker dialog."""

    def __init__(self, parent=None, color=(255, 0, 0), alpha=False,
                 title=_("Color Chooser")):
        """
        Create a ColorPicker dialog.

        Arguments:
            * parent: parent window
            * color: initially selected color in rgb or hexa format
            * alpha: alpha channel support (boolean)
            * title: dialog title
        """
        tk.Toplevel.__init__(self, parent)

        self.title(title)
github TkinterEP / ttkwidgets / ttkwidgets / color / colorsquare.py View on Github external
tkcolorpicker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see .

Color square gradient with selection cross
"""


from .functions import tk, round2, rgb_to_hexa, hue2col, rgb_to_hsv


class ColorSquare(tk.Canvas):
    """Square color gradient with selection cross."""

    def __init__(self, parent, hue, color=None, height=256, width=256, **kwargs):
        """
        Create a ColorSquare.

        :param parent: parent widget
        :type parent: widget
        :param hue: hue (between 0 and 360) of the color square gradient
                   (color in top right corner is (hue, 100, 100) in HSV)
        :type hue: int
        :param color: initially selected color given in HSV format
        :type color: tuple[int]
        :param height: height of the widget in pixels
        :type height: int
        :param width: width of the widget in pixels