def __init__(self,
                 parent,
                 tempColor=4000,
                 height=11,
                 width=500,
                 variable=None,
                 **kwargs):
        """
        Create a TemperatureGradBar.

        Keyword arguments:
            * parent: parent window
            * tempColor: initially selected tempColor 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:
                tempColor = int(variable.get())
            except Exception:
                pass
        else:
            self._variable = tk.IntVar(self)

        tempColor -= 1500
        if tempColor > 5200:
            tempColor = 5200
        elif tempColor < 1500:
            tempColor = 1500

        try:
            self._variable.trace_add("write", self._update_temperature)
        except Exception:
            self._variable.trace("w", self._update_temperature)

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

        self.bind('<Configure>', lambda e: self._draw_gradient(tempColor))
        self.bind('<ButtonPress-1>', self._on_click)
        self.bind('<B1-Motion>', self._on_move)
Exemple #2
0
    def __init__(self,
                 parent,
                 hue=0,
                 value=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)
        except Exception:
            self._variable.trace("w", self._update_hue)

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

        self.bind('<Configure>', lambda e: self._draw_gradient(hue))
        self.bind('<ButtonPress-1>', self._on_click)
        self.bind('<B1-Motion>', self._on_move)
Exemple #3
0
    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.

        Keyword arguments:
            * parent: parent window
            * alpha: initially selected alpha value
            * color: gradient color
            * 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.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('<Configure>', lambda e: self._draw_gradient(alpha, color))
        self.bind('<ButtonPress-1>', self._on_click)
        self.bind('<B1-Motion>', self._on_move)