How to use the ttkwidgets.color.functions.hue2col 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 / tests / test_color_widgets.py View on Github external
def test_hue2col(self):
        self.assertEqual(tkf.hue2col(0), (255, 0, 0))
        self.assertRaises(ValueError, tkf.hue2col, 365)
        self.assertRaises(ValueError, tkf.hue2col, -20)
github TkinterEP / ttkwidgets / tests / test_color_widgets.py View on Github external
def test_hue2col(self):
        self.assertEqual(tkf.hue2col(0), (255, 0, 0))
        self.assertRaises(ValueError, tkf.hue2col, 365)
        self.assertRaises(ValueError, tkf.hue2col, -20)
github TkinterEP / ttkwidgets / ttkwidgets / color / colorsquare.py View on Github external
def _fill(self):
        """Create the gradient."""
        r, g, b = hue2col(self._hue)
        width = self.winfo_width()
        height = self.winfo_height()
        h = float(height - 1)
        w = float(width - 1)
        if height:
            c = [(r + i / h * (255 - r), g + i / h * (255 - g), b + i / h * (255 - b)) for i in range(height)]
            data = []
            for i in range(height):
                line = []
                for j in range(width):
                    rij = round2(j / w * c[i][0])
                    gij = round2(j / w * c[i][1])
                    bij = round2(j / w * c[i][2])
                    color = rgb_to_hexa(rij, gij, bij)
                    line.append(color)
                data.append("{" + " ".join(line) + "}")
github TkinterEP / ttkwidgets / ttkwidgets / color / gradientbar.py View on Github external
def _draw_gradient(self, hue):
        """Draw the gradient and put the cursor on hue."""
        self.delete("gradient")
        self.delete("cursor")
        del self.gradient
        width = self.winfo_width()
        height = self.winfo_height()

        self.gradient = tk.PhotoImage(master=self, width=width, height=height)

        line = []
        for i in range(width):
            line.append(rgb_to_hexa(*hue2col(float(i) / width * 360)))
        line = "{" + " ".join(line) + "}"
        self.gradient.put(" ".join([line for j in range(height)]))
        self.create_image(0, 0, anchor="nw", tags="gardient",
                          image=self.gradient)
        self.lower("gradient")

        x = hue / 360. * width
        self.create_line(x, 0, x, height, width=2, tags='cursor')
github TkinterEP / ttkwidgets / ttkwidgets / color / colorsquare.py View on Github external
: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
        :type width: int
        :param kwargs: options to be passed on to the :class:`tk.Canvas` initializer
        """
        tk.Canvas.__init__(self, parent, height=height, width=width, **kwargs)
        self.bg = tk.PhotoImage(width=width, height=height, master=self)
        self._hue = hue
        if not color:
            color = hue2col(self._hue)
        self.bind('', lambda e: self._draw(color))
        self.bind('', self._on_click)
        self.bind('', self._on_move)