Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

RangeSlider

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

RangeSlider

Python tkinter widget for range selection in slider widget structure with two handles

  • 2023.7.2
  • PyPI
  • Socket score

Maintainers
1

PyPi Downloads

RangeSlider 2023.07.2

Range selection widget for Python Tkinter GUI developement in slider widget structure with two handles.

Updates and Fixes in v2023.07.2 w.r.t v2023.07.1

Updates and Fixes in v2023.07.1 w.r.t v2022.12.1

Updates and Fixes in v2022.12.1 w.r.t. v2021.7.4

Note: In order to set the initial values -- declare initial value to the handle variable, if undeclared both handles will be set to min_val. See example in Usage section.

Features:

  • Range selection
  • Vertical as well as horizontal widget
  • Option for showing current value of handle
  • Customizable handle with default circular handle offering color choice or using image as handle
  • Ability to bind a tkinter variable, making it easier to check for slider movement
  • Custom font and position for value text
  • Customizable value precision
  • Custom suffix option
  • Many others...

Preview

[preview.png] image file in repository.

Usage

Importing required sliders

For horizontal RangeSlider:

from RangeSlider.RangeSlider import RangeSliderH 

For vertical RangeSlider:

from RangeSlider.RangeSlider import RangeSliderV

For both horizontal and vertical RangeSlider:

from RangeSlider.RangeSlider import RangeSliderH, RangeSliderV

Creating Simple RangeSlider widget:

from tkinter.ttk import *
import tkinter as tk
 
root = tk.Tk()
 
hLeft = tk.DoubleVar(value = 0.2)  #left handle variable initialised to value 0.2
hRight = tk.DoubleVar(value = 0.85)  #right handle variable initialised to value 0.85
hSlider = RangeSliderH( root , [hLeft, hRight] , padX = 12)   #horizontal slider, [padX] value might be needed to be different depending on system, font and handle size. Usually [padX] = 12 serves,
                                                              #otherwise a recommended value will be shown through an error message
hSlider.pack()   # or grid or place method could be used

vBottom = tk.DoubleVar(value = 0)   #bottom handle variable
vTop = tk.DoubleVar(value = 1)   #top handle variable
vSlider = RangeSliderV( root, [vBottom, vTop] , padY = 12)    #vertical slider, [padY] value might be needed to be different depending on system, font and handle size. Usually [padY] = 12 serves,
                                                              #otherwise a recommended value will be shown through an error message
vSlider.pack()  # or grid or place method could be used

root.mainloop()

Getting current value

print ( hSlider.getValues() )  #return type list of format [ left handle value, right handle value ]
print ( vSlider.getValues() )  #return type list of format [ bottom handle value, top handle value ]

Force value

hSlider.forceValues([0.2, 0.67])  #returns None
vSlider.forceValues([0.62, 0.85])  #returns None

Callback on value change

def doSomething():
    print ('I was called.')

hLeft.trace_add('w', doSomething)
hRight.trace_add('w', doSomething)
vBottom.trace_add('w', doSomething)
vTop.trace_add('w', doSomething)

Attributes

For RangeSliderH:

AttributeDefault ValueAcceptable Value(s) or DescriptionRelease Comment
masterN/Aparent like Tk instance, TopLevel, or Frame etc.v2021.7.4
variablesN/Alist of DoubleVar of length two in order of left handle and right handlev2021.7.4
Width400width of widget in pxv2021.7.4
Height80height of widget in pxv2021.7.4
min_val0minimum valuev2021.7.4
max_val1maximum valuev2021.7.4
padX3padding from both left and right in pxv2021.7.4
image_anchorRCENTERanchor value for right handle if image is used as handle - N, NE, E, SE, S, SW, W, NW, CENTERv2021.7.4
image_anchorLCENTERanchor value for left handle if image is used as handle - N, NE, E, SE, S, SW, W, NW, CENTERv2021.7.4
imageLNonePhotoImage instance for imaged left handlev2021.7.4
imageRNonePhotoImage instance for imaged right handlev2021.7.4
autoTrueTrue for automatic circular colored handle, False for imaged handlev2021.7.4
line_width3width of widget track in pxv2021.7.4
bar_radius10radius of outer circle of handlev2021.7.4
bar_color_inner'#5c8a8a'hex value of color for inner circle in string formatv2021.7.4
bar_color_outer'#c2d6d6'hex value of color for inner circle in string formatv2021.7.4
line_s_color'#0a50ff'hex value of color for selected portion for widget track in string formatv2021.7.4
line_color'#476b6b'hex value of color for unselected portion for widget track in string formatv2021.7.4
bgColor'#ffffff'hex value of color for background of widget in string formatv2021.7.4
step_marker_color'#ffffff'hex value of color in string format for steps marked on widget barv2022.12.1
font_color'#000000'hex value of color for font of widget in string formatv2022.12.1
show_valueTrueTrue if current value of handle are intended; otherwise Falsev2021.7.4
digit_precision'.1f'precision format for shown valuev2021.7.4
valueSide'TOP''TOP' if shown value intended above the handle or 'BOTTOM' if shown value intended below the handlev2021.7.4
font_family'Times'font family ( all font families supported by tkinter are acceptable )v2021.7.4
font_size16font size in ptv2021.7.4
suffix""suffix for shown valuev2021.7.4
step_size0step size of handle movement, step_size equal to 0 implies continuous movement subject to system architecture floating point resolutionv2022.12.1
step_markerFalseTrue if to display step markers on bar; otherwise Falsev2022.12.1
cross_each_otherFalseTrue if handles can cross each otherv2022.12.1

For RangeSliderV:

AttributeDefault ValueAcceptable Value(s)Release Comment
masterN/Aparent like Tk instance, TopLevel, or Frame etc.v2021.7.4
variablesN/Alist of DoubleVar of length two in order of lower handle and upper handlev2021.7.4
Width80width of widget in pxv2021.7.4
Height400height of widget in pxv2021.7.4
min_val0minimum valuev2021.7.4
max_val1maximum valuev2021.7.4
padY3padding from both top and bottom in pxv2021.7.4
image_anchorUCENTERanchor value for upper handle if image is used as handle - N, NE, E, SE, S, SW, W, NW, CENTERv2021.7.4
image_anchorLCENTERanchor value for lower handle if image is used as handle - N, NE, E, SE, S, SW, W, NW, CENTERv2021.7.4
imageLNonePhotoImage instance for imaged lower handlev2021.7.4
imageUNonePhotoImage instance for imaged upper handlev2021.7.4
autoTrueTrue for automatic circular colored handle, False for imaged handlev2021.7.4
line_width3width of widget track in pxv2021.7.4
bar_radius10radius of outer circle of handlev2021.7.4
bar_color_inner'#5c8a8a'hex value of color for inner circle in string formatv2021.7.4
bar_color_outer'#c2d6d6'hex value of color for inner circle in string formatv2021.7.4
line_s_color'#0a50ff'hex value of color for selected portion for widget track in string formatv2021.7.4
line_color'#476b6b'hex value of color for unselected portion for widget track in string formatv2021.7.4
bgColor'#ffffff'hex value of color for background of widget in string formatv2021.7.4
step_marker_color'#ffffff'hex value of color in string format for steps marked on widget barv2022.12.1
font_color'#000000'hex value of color for font of widget in string formatv2022.12.1
show_valueTrueTrue if current value of handle are intended; otherwise Falsev2021.7.4
digit_precision'.1f'precision format for shown valuev2021.7.4
valueSide'TOP''TOP' if shown value intended above the handle or 'BOTTOM' if shown value intended below the handlev2021.7.4
font_family'Times'font family ( all font families supported by tkinter are acceptable )v2021.7.4
font_size16font size in ptv2021.7.4
suffix""suffix for shown valuev2021.7.4
step_size0step size of handle movement, step_size equal to 0 implies continuous movement subject to system architecture floating point resolutionv2022.12.1
step_markerFalseTrue if to display step markers on bar; otherwise Falsev2022.12.1
cross_each_otherFalseTrue if handles can cross each otherv2022.12.1

Additional Notes for attributes

  • if show_value is False, digit_precision, valueSide, font_family, font_size and suffix have no effect
  • if auto is True, imageL, imageU, image_anchorL, image_anchorR and image_anchorU have no effect
  • if auto is False, bar_radius, bar_color_inner, bar_color_outer have no effect
  • if step_size is zero, step_marker will not be made

Exceptions raised

ConditionException
if auto is True and either imageL or imageU or imageR or combination out of three is also givenException raised: "Can't decide if to use auto shape or images!"
if auto is False and one of the image handles is missingException raised: "Handle for one image missing."
if auto is False and dimensions for both handles provided are not sameException raised : "Image dimensions incompatible, both handles should have same height and width respectively."
if Width or Height or padX or padY are not sufficient to render the widget with all features visible safelyException raised : $dimension$ not suitable with suggestions to avoid it

Functions

FunctionArgumentsOutput Format
getValues()NILvalue of handle variables in list format in the same order as given in object definition, returned values lie between min_val and max_val
getPos()NILnormalised value of handle variables in list format in the same order as given in object definition, returned values lie between 0 and 1
forceValues(values)values : a list of two values each indicating value of handle, values must be between min_val and max_valreturn None
forcePos(pos)pos : a list of two normalised values each indicating value of handle, values must be between 0 and 1return None

Note: The relation between value ($v_i$) and normalised value ($n_i$) of $i^{th}$ handle defined for a slider with max_val of $v_<$ and min_val of $v_>$ is given by:

$\begin{equation} n_i = \frac{v_i - v_>}{v_<-v_>} \end{equation}$

Words of Developer

This is the second version of this library. It is one of its kind widget for tkinter. When I was developing a tool for my college project I found that at the time no inbuilt or external tool is available for tkinter allowing range selection. However, range selection is a high demand tool specially for applications dealing with data visualizations. I would appreciate any developer from any community who wants to contribute to this project.

I thank RWitak and Sebastian for contributing to this project.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc