Search code examples
pythontkinterrangeslider

how to use range slider in tkinter


I am trying to use a range slider widget for my problem. I looked into the net but I couldn't find an example of this widget RangeSliderH. I found this library for that. https://pypi.org/project/RangeSlider/

Does anyone know how to update this code to make that show on the screen?currently I am getting this error: Exception: padX too small, value won't be visible completely, expected padX to be atleast 16.96px

from RangeSlider.RangeSlider import RangeSliderH

from tkinter import *
import tkinter as tk

root = tk.Tk()
root.geometry("750x750")

hVar1 = DoubleVar()  # left handle variable
hVar2 = DoubleVar()  # right handle variable

rs1 = RangeSliderH(root, [hVar1, hVar2], Width=400, Height=60, min_val=0, max_val=400, show_value= True)
rs1.pack()

root.mainloop()

Solution

  • Just follow the suggestion in the exception message to set padX to value >= 16.96.

    However after fixing it, another exception on Height is raised:

    Exception: Dimensions incompatible, consider decreasing bar_radius or consider increasing widget height, as per given configuration height should be atleast .63.56px.
    

    Adjust the value of Height as suggested in the exception message as well. So the final fix is:

    rs1 = RangeSliderH(root, [hVar1, hVar2], Width=400, Height=65, padX=17, min_val=0, max_val=400, show_value= True)