Python tkinter.ttk.Scale() Examples

The following are 22 code examples of tkinter.ttk.Scale(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tkinter.ttk , or try the search function .
Example #1
Source File: gui.py    From stochopy with MIT License 8 votes vote down vote up
def _scale(self, from_, to, resolution, variable, position, command = None,
               kwargs = {}):
        if command is None:
            command = lambda s: variable.set(round(float(s), 3))
        scale = ttk.Scale(self.frame1.sliders, from_ = from_, to = to, variable = variable,
                          orient = "horizontal", length = 20, command = command,
                          takefocus = False, **kwargs)
        if position == 1:
            scale.place(relwidth = 0.35, relx = 0, x = 0, y = 25, anchor = "nw")
        elif position == 2:
            scale.place(relwidth = 0.35, relx = 0, x = 0, y = 70, anchor = "nw")
        elif position == 3:
            scale.place(relwidth = 0.35, relx = 0.5, x = 0, y = 25, anchor = "nw")
        elif position == 4:
            scale.place(relwidth = 0.35, relx = 0.5, x = 0, y = 70, anchor = "nw")
        return scale 
Example #2
Source File: widget_tests.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def test_keys(self):
        widget = self.create()
        keys = widget.keys()
        # XXX
        if not isinstance(widget, Scale):
            self.assertEqual(sorted(keys), sorted(widget.configure()))
        for k in keys:
            widget[k]
        # Test if OPTIONS contains all keys
        if test.support.verbose:
            aliases = {
                'bd': 'borderwidth',
                'bg': 'background',
                'fg': 'foreground',
                'invcmd': 'invalidcommand',
                'vcmd': 'validatecommand',
            }
            keys = set(keys)
            expected = set(self.OPTIONS)
            for k in sorted(keys - expected):
                if not (k in aliases and
                        aliases[k] in keys and
                        aliases[k] in expected):
                    print('%s.OPTIONS doesn\'t contain "%s"' %
                          (self.__class__.__name__, k)) 
Example #3
Source File: widget_tests.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def checkParam(self, widget, name, value, *, expected=_sentinel,
                   conv=False, eq=None):
        widget[name] = value
        if expected is _sentinel:
            expected = value
        if conv:
            expected = conv(expected)
        if self._stringify or not self.wantobjects:
            if isinstance(expected, tuple):
                expected = tkinter._join(expected)
            else:
                expected = str(expected)
        if eq is None:
            eq = tcl_obj_eq
        self.assertEqual2(widget[name], expected, eq=eq)
        self.assertEqual2(widget.cget(name), expected, eq=eq)
        # XXX
        if not isinstance(widget, Scale):
            t = widget.configure(name)
            self.assertEqual(len(t), 5)
            self.assertEqual2(t[4], expected, eq=eq) 
Example #4
Source File: control_helper.py    From faceswap with GNU General Public License v3.0 6 votes vote down vote up
def config_cleaner(widget):
        """ Some options don't like to be copied, so this returns a cleaned
            configuration from a widget
            We use config() instead of configure() because some items (ttk Scale) do
            not populate configure()"""
        new_config = dict()
        for key in widget.config():
            if key == "class":
                continue
            val = widget.cget(key)
            # Some keys default to "" but tkinter doesn't like to set config to this value
            # so skip them to use default value.
            if key in ("anchor", "justify", "compound") and val == "":
                continue
            val = str(val) if isinstance(val, Tcl_Obj) else val
            # Return correct command from master command dict
            val = _RECREATE_OBJECTS["commands"][val] if key == "command" and val != "" else val
            new_config[key] = val
        return new_config 
Example #5
Source File: widget_tests.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def checkParam(self, widget, name, value, *, expected=_sentinel,
                   conv=False, eq=None):
        widget[name] = value
        if expected is _sentinel:
            expected = value
        if conv:
            expected = conv(expected)
        if self._stringify or not self.wantobjects:
            if isinstance(expected, tuple):
                expected = tkinter._join(expected)
            else:
                expected = str(expected)
        if eq is None:
            eq = tcl_obj_eq
        self.assertEqual2(widget[name], expected, eq=eq)
        self.assertEqual2(widget.cget(name), expected, eq=eq)
        # XXX
        if not isinstance(widget, Scale):
            t = widget.configure(name)
            self.assertEqual(len(t), 5)
            self.assertEqual2(t[4], expected, eq=eq) 
Example #6
Source File: widget_tests.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
def checkParam(self, widget, name, value, *, expected=_sentinel,
                   conv=False, eq=None):
        widget[name] = value
        if expected is _sentinel:
            expected = value
        if conv:
            expected = conv(expected)
        if self._stringify or not self.wantobjects:
            if isinstance(expected, tuple):
                expected = tkinter._join(expected)
            else:
                expected = str(expected)
        if eq is None:
            eq = tcl_obj_eq
        self.assertEqual2(widget[name], expected, eq=eq)
        self.assertEqual2(widget.cget(name), expected, eq=eq)
        # XXX
        if not isinstance(widget, Scale):
            t = widget.configure(name)
            self.assertEqual(len(t), 5)
            self.assertEqual2(t[4], expected, eq=eq) 
Example #7
Source File: test_widgets.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def create(self, **kwargs):
        return ttk.Scale(self.root, **kwargs) 
Example #8
Source File: replayer.py    From thonny with MIT License 5 votes vote down vote up
def __init__(self, master, **kw):
        ttk.Frame.__init__(self, master=master, **kw)

        self.toggle_button = ttk.Button(self, text="Play")
        self.speed_scale = ttk.Scale(self, from_=1, to=100, orient=tk.HORIZONTAL)

        self.toggle_button.grid(row=0, column=0, sticky=tk.NSEW, pady=(10, 0), padx=(0, 5))
        self.speed_scale.grid(row=0, column=1, sticky=tk.NSEW, pady=(10, 0), padx=(5, 0))

        self.columnconfigure(1, weight=1) 
Example #9
Source File: test_widgets.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def create(self, **kwargs):
        return ttk.Scale(self.root, **kwargs) 
Example #10
Source File: control_helper.py    From faceswap with GNU General Public License v3.0 5 votes vote down vote up
def slider_control(self):
        """ A slider control with corresponding Entry box """
        logger.debug("Add slider control to Options Frame: (widget: '%s', dtype: %s, "
                     "rounding: %s, min_max: %s)", self.option.name, self.option.dtype,
                     self.option.rounding, self.option.min_max)
        validate = self.slider_check_int if self.option.dtype == int else self.slider_check_float
        vcmd = (self.frame.register(validate))
        tbox = ttk.Entry(self.frame,
                         width=8,
                         textvariable=self.option.tk_var,
                         justify=tk.RIGHT,
                         font=get_config().default_font,
                         validate="all",
                         validatecommand=(vcmd, "%P"))
        tbox.pack(padx=(0, 5), side=tk.RIGHT)
        cmd = partial(set_slider_rounding,
                      var=self.option.tk_var,
                      d_type=self.option.dtype,
                      round_to=self.option.rounding,
                      min_max=self.option.min_max)
        ctl = ttk.Scale(self.frame, variable=self.option.tk_var, command=cmd)
        _add_command(ctl.cget("command"), cmd)
        rc_menu = _get_contextmenu(tbox)
        rc_menu.cm_bind()
        ctl["from_"] = self.option.min_max[0]
        ctl["to"] = self.option.min_max[1]
        logger.debug("Added slider control to Options Frame: %s", self.option.name)
        return ctl 
Example #11
Source File: control_helper.py    From faceswap with GNU General Public License v3.0 5 votes vote down vote up
def scale_column_width(original_size, original_fontsize):
        """ Scale the column width based on selected font size """
        font_size = get_config().user_config_dict["font_size"]
        if font_size == original_fontsize:
            return original_size
        scale = 1 + (((font_size / original_fontsize) - 1) / 2)
        retval = round(original_size * scale)
        logger.debug("scaled column width: (old_width: %s, scale: %s, new_width:%s)",
                     original_size, scale, retval)
        return retval 
Example #12
Source File: display_command.py    From faceswap with GNU General Public License v3.0 5 votes vote down vote up
def add_option_smoothing(self):
        """ Add refresh button to refresh graph immediately """
        logger.debug("Adding Smoothing Slider")
        tk_var = get_config().tk_vars["smoothgraph"]
        min_max = (0, 0.99)
        hlp = "Set the smoothing amount. 0 is no smoothing, 0.99 is maximum smoothing."

        ctl_frame = ttk.Frame(self.optsframe)
        ctl_frame.pack(padx=2, side=tk.RIGHT)

        lbl = ttk.Label(ctl_frame, text="Smoothing Amount:", anchor=tk.W)
        lbl.pack(pady=5, side=tk.LEFT, anchor=tk.N, expand=True)

        tbox = ttk.Entry(ctl_frame, width=6, textvariable=tk_var, justify=tk.RIGHT)
        tbox.pack(padx=(0, 5), side=tk.RIGHT)

        ctl = ttk.Scale(
            ctl_frame,
            variable=tk_var,
            command=lambda val, var=tk_var, dt=float, rn=2, mm=(0, 0.99):
            set_slider_rounding(val, var, dt, rn, mm))
        ctl["from_"] = min_max[0]
        ctl["to"] = min_max[1]
        ctl.pack(padx=5, pady=5, fill=tk.X, expand=True)
        for item in (tbox, ctl):
            Tooltip(item,
                    text=hlp,
                    wraplength=200)
        logger.debug("Added Smoothing Slider") 
Example #13
Source File: Controls.py    From Python-Media-Player with Apache License 2.0 5 votes vote down vote up
def create_control_panel(self):
        frame=Tkinter.LabelFrame(self.root)
        frame.pack(expand='yes',fill='x',side='top')
        add_fileicon=Tkinter.PhotoImage(file="../Icons/add_file.gif")
        add_directoryicon=Tkinter.PhotoImage(file="../Icons/add_directory.gif")
        exiticon=Tkinter.PhotoImage(file="../Icons/exit.gif")
        playicon=Tkinter.PhotoImage(file="../Icons/play.gif")
        pauseicon=Tkinter.PhotoImage(file="../Icons/pause.gif")
        stopicon=Tkinter.PhotoImage(file="../Icons/stop.gif")
        rewindicon=Tkinter.PhotoImage(file="../Icons/rewind.gif")
        fast_forwardicon=Tkinter.PhotoImage(file="../Icons/fast_forward.gif")
        previous_trackicon=Tkinter.PhotoImage(file="../Icons/previous_track.gif")
        next_trackicon=Tkinter.PhotoImage(file="../Icons/next_track.gif")
        self.muteicon=Tkinter.PhotoImage(file="../Icons/mute.gif")
        self.unmuteicon=Tkinter.PhotoImage(file="../Icons/unmute.gif")
        delete_selectedicon=Tkinter.PhotoImage(file="../Icons/delete_selected.gif")

        list_file=[
            (playicon,'self.play'),
            (pauseicon,'self.pause'),
            (stopicon,'self.stop'),
            (previous_trackicon,'self.previous'),
            (rewindicon,'self.rewind'),
            (fast_forwardicon,'self.fast'),
            (next_trackicon,'self.Next'),]
        for i,j in list_file:
            storeobj=ttk.Button(frame, image=i,command=eval(j))
            storeobj.pack(side='left')
            storeobj.image=i
        self.volume_label=Tkinter.Button(frame,image=self.unmuteicon)
        self.volume_label.image=self.unmuteicon
        
        volume=ttk.Scale(frame,from_=Volume_lowest_value, to=Volume_highest_value ,variable=self.var, command=self.update_volume)
        volume.pack(side='right', padx=10, )
        self.volume_label.pack(side='right')
        return 
Example #14
Source File: box.py    From synthesizer with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, master, title):
        self.title = title
        super().__init__(master, text=title, padding=4)
        self.player = None   # will be connected later
        self.volumeVar = tk.DoubleVar(value=100)
        self.volumefilter = VolumeFilter()
        ttk.Label(self, text="title / artist / album").pack()
        self.titleLabel = ttk.Label(self, relief=tk.GROOVE, width=22, anchor=tk.W)
        self.titleLabel.pack()
        self.artistLabel = ttk.Label(self, relief=tk.GROOVE, width=22, anchor=tk.W)
        self.artistLabel.pack()
        self.albumlabel = ttk.Label(self, relief=tk.GROOVE, width=22, anchor=tk.W)
        self.albumlabel.pack()
        f = ttk.Frame(self)
        ttk.Label(f, text="time left: ").pack(side=tk.LEFT)
        self.timeleftLabel = ttk.Label(f, relief=tk.GROOVE, anchor=tk.CENTER)
        self.timeleftLabel.pack(side=tk.RIGHT, fill=tk.X, expand=True)
        f.pack(fill=tk.X)
        f = ttk.Frame(self)
        ttk.Label(f, text="V: ").pack(side=tk.LEFT)
        scale = ttk.Scale(f, from_=0, to=150, length=120, variable=self.volumeVar, command=self.on_volumechange)
        scale.bind("<Double-1>", self.on_dblclick_vol)
        scale.pack(side=tk.LEFT)
        self.volumeLabel = ttk.Label(f, text="???%")
        self.volumeLabel.pack(side=tk.RIGHT)
        f.pack(fill=tk.X)
        ttk.Button(self, text="Skip", command=lambda s=self: s.player.skip(s)).pack(pady=4)
        self.volume = 100
        self.stateLabel = tk.Label(self, text="STATE", relief=tk.SUNKEN, border=1)
        self.stateLabel.pack()
        self._track = None
        self._time = None
        self._stream = None
        self._state = self.state_needtrack
        self.state = self.state_needtrack
        self.xfade_state = self.state_xfade_nofade
        self.xfade_started = None
        self.xfade_start_volume = None
        self.playback_started = None
        self.track_duration = None 
Example #15
Source File: program8.py    From python-gui-demos with MIT License 5 votes vote down vote up
def __init__(self, master):
        ttk.Label(master, text = "PROGRESS CONTROL").pack()
        
        # Inderterminant Progressbar
        ttk.Label(master, text = 'Inderterminant Progress').pack()
        self.prgrsbr_indtr = ttk.Progressbar(master, orient = tk.HORIZONTAL, length = 300, mode = 'indeterminate')
        self.prgrsbr_indtr.pack()
        self.checkpbi = tk.StringVar()
        self.checkpbi.set("Start")
        
        # Button
        self.btn1 = ttk.Button(master, text = "{} Inderterminant Progress Bar".format(self.checkpbi.get()), command = self.btn1cmd)
        self.btn1.pack()

        # Derterminant progress
        ttk.Label(master, text = 'Derterminant Progress').pack()
        self.prgrsbr_dtr = ttk.Progressbar(master, orient=tk.HORIZONTAL, length = 300, mode = 'determinate')
        self.prgrsbr_dtr.pack()
        self.prgrsbr_dtr.config(maximum = 10.0, value = 2.0)    # notice both these properties have float values
        
        # Button
        ttk.Button(master, text = 'Reset Progress Bar to zero', command = self.resetProgressBarVal).pack()
        
        # Button
        ttk.Button(master, text = 'Increase Progress Bar by 2', command = self.shift2ProgressBarVal).pack()
        
        # create double variable
        self.prgrsBrVal = tk.DoubleVar()
        
        self.prgrsbr_dtr.config(variable = self.prgrsBrVal) # set variable property of progressbar to look at DoubleVar()
        
        # Scale widget
        self.scalebar = ttk.Scale(master, orient = tk.HORIZONTAL, length = 400, variable=self.prgrsBrVal, from_ = 0.0, to= 10.0)
        self.scalebar.pack()
        
        # Label to display current value of scalebar
        ttk.Label(master, text = "Current value of Progress Bar is as below:").pack()
        self.scalebar_label = ttk.Label(master, textvariable = self.prgrsBrVal)
        self.scalebar_label.pack() 
Example #16
Source File: test_widgets.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def create(self, **kwargs):
        return ttk.Scale(self.root, **kwargs) 
Example #17
Source File: scaleentry.py    From ttkwidgets with GNU General Public License v3.0 5 votes vote down vote up
def config_scale(self, cnf={}, **kwargs):
        """Configure resources of the Scale widget."""
        self._scale.config(cnf, **kwargs)
        # Update self._variable limits in case the ones of the scale have changed
        self._variable.configure(high=self._scale['to'],
                                 low=self._scale['from'])
        if 'orient' in cnf or 'orient' in kwargs:
            self._grid_widgets() 
Example #18
Source File: scaleentry.py    From ttkwidgets with GNU General Public License v3.0 5 votes vote down vote up
def _on_scale(self, event):
        """
        Callback for the Scale widget, inserts an int value into the Entry.

        :param event: Tkinter event
        """
        self._entry.delete(0, tk.END)
        self._entry.insert(0, str(self._variable.get())) 
Example #19
Source File: scaleentry.py    From ttkwidgets with GNU General Public License v3.0 5 votes vote down vote up
def _on_entry(self, event):
        """
        Callback for the Entry widget, sets the Scale variable to the appropriate value.
        
        :param event: Tkinter event
        """
        contents = self._entry.get()
        if contents == "":
            return
        try:
            value = self._variable.set(int(contents))
        except ValueError:
            value = None
        if not value:
            self._on_scale(None) 
Example #20
Source File: scaleentry.py    From ttkwidgets with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, master=None, scalewidth=50, entrywidth=5, from_=0, to=50,
                 orient=tk.HORIZONTAL, compound=tk.RIGHT, entryscalepad=0, **kwargs):
        """
        Create a ScaleEntry.
        
        :param master: master widget
        :type master: widget
        :param scalewidth: width of the Scale in pixels
        :type scalewidth: int
        :param entrywidth: width of the Entry in characters
        :type entrywidth: int
        :param from\_: start value of the scale
        :type from\_: int
        :param to: end value of the scale
        :type to: int
        :param orient: scale orientation. Supports :obj:`tk.HORIZONTAL` and :obj:`tk.VERTICAL`
        :type orient: str
        :param compound: side the Entry must be on. Supports :obj:`tk.LEFT`,
                         :obj:`tk.RIGHT`, :obj:`tk.TOP` and :obj:`tk.BOTTOM`
        :type compound: str
        :param entryscalepad: space between the entry and the scale
        :type entryscalepad: int
        :param kwargs: keyword arguments passed on to the :class:`ttk.Frame` initializer
        """
        ttk.Frame.__init__(self, master, **kwargs)
        if compound is not tk.RIGHT and compound is not tk.LEFT and compound is not tk.TOP and \
           compound is not tk.BOTTOM:
            raise ValueError("Invalid value for compound passed {0}".format(compound))
        self.__compound = compound
        if not isinstance(entryscalepad, int):
            raise TypeError("entryscalepad not of int type")
        self.__entryscalepad = entryscalepad
        self._variable = self.LimitedIntVar(from_, to)
        self._scale = ttk.Scale(self, from_=from_, to=to, length=scalewidth,
                                orient=orient, command=self._on_scale,
                                variable=self._variable)
        # Note that the textvariable keyword argument is not used to pass the LimitedIntVar
        self._entry = ttk.Entry(self, width=entrywidth)
        self._entry.insert(0, str(from_))
        self._entry.bind("<KeyRelease>", self._on_entry)
        self._grid_widgets() 
Example #21
Source File: tickscale.py    From ttkwidgets with GNU General Public License v3.0 5 votes vote down vote up
def _update_slider_length_vertical(self):
        """
        Measure the length of the slider and update the value of self._sliderlength.

        self.scale.identify(x, y) is used to find the first and last pixels of
        the slider. Indeed, self.scale.identify(x, y) returns the element
        of the ttk.Scale to which the pixel (x, y) belongs. So, the length of
        the slider is determined by scanning vertically the pixels of the scale.
        """
        if not self.scale.identify(2, 2):
            # if self.scale.identify(2, 2) is an empty string it means that the scale
            # is not displayed yet so we cannot measure the length of the slider,
            # so wait for the scale to be properly displayed.
            # binding to <Map> event does not work, it can still be to soon to
            # get any result from identify
            self.after(10, self._update_slider_length_vertical)
        else:
            h = self.scale.winfo_height()
            i = 0
            # find the first pixel of the slider
            while i < h and 'slider' not in self.scale.identify(2, i):
                # increment i until the pixel (2, i) belongs to the slider
                i += 1
            j = i
            # find the last pixel of the slider
            while j < h and 'slider' in self.scale.identify(2, j):
                # increment j until the pixel (2, j) no longer belongs to the slider
                j += 1
            if j == i:
                # the length of the slider was not determined properly,
                # so the value of the sliderlength from the style is used
                self._sliderlength = self.style.lookup(self._style_name, 'sliderlength', default=30)
            else:
                self._sliderlength = j - i
            # update ticks and label placement
            self._update_display() 
Example #22
Source File: tickscale.py    From ttkwidgets with GNU General Public License v3.0 5 votes vote down vote up
def _update_slider_length_horizontal(self):
        """
        Measure the length of the slider and update the value of self._sliderlength.

        self.scale.identify(x, y) is used to find the first and last pixels of
        the slider. Indeed, self.scale.identify(x, y) returns the element
        of the ttk.Scale to which the pixel (x, y) belongs. So, the length of
        the slider is determined by scanning horizontally the pixels of the scale.
        """
        if not self.scale.identify(2, 2):
            # if self.scale.identify(2, 2) is an empty string it means that the scale
            # is not displayed yet so we cannot measure the length of the slider,
            # so wait for the scale to be properly displayed.
            # binding to <Map> event does not work, it can still be to soon to
            # get any result from identify
            self.after(10, self._update_slider_length_horizontal)
        else:
            w = self.scale.winfo_width()
            i = 0
            # find the first pixel of the slider
            while i < w and 'slider' not in self.scale.identify(i, 2):
                # increment i until the pixel (i, 2) belongs to the slider
                i += 1
            j = i
            # find the last pixel of the slider
            while j < w and 'slider' in self.scale.identify(j, 2):
                # increment j until the pixel (2, j) no longer belongs to the slider
                j += 1
            if j == i:
                # the length of the slider was not determined properly,
                # so the value of the sliderlength from the style is used
                self._sliderlength = self.style.lookup(self._style_name, 'sliderlength', default=30)
            else:
                # update ticks and label placement
                self._sliderlength = j - i
            self._update_display()