harshvinay752 / RangeSlider

Python tkinter widget for range selection in slider widget structure with two handles
MIT License
11 stars 4 forks source link

Handle variables can't be initialised #7

Closed PetervanLunteren closed 1 year ago

PetervanLunteren commented 1 year ago

@harshvinay752 @RWitak @sebasj13

I'm having trouble with initialising the handle values. It seems like the values are overwritten when the slider is created. Any help would be appreciated. Thanks!

    min_val = DoubleVar(value = 0.1)
    max_val = DoubleVar(value = 0.9)
    print(f"min_val 1: {min_val.get()}")
    print(f"max_val 1: {max_val.get()}")

    min_val.set(0.2)
    max_val.set(0.8)
    print(f"min_val 2: {min_val.get()}")
    print(f"max_val 2: {max_val.get()}")

    rsl = RangeSliderH(frame, [max_val, min_val], padX=23, digit_precision='.2f')
    print(f"min_val 3: {min_val.get()}")
    print(f"max_val 3: {max_val.get()}")

    rsl.pack()

   #> min_val 1: 0.1
   #> max_val 1: 0.9
   #> min_val 2: 0.2
   #> max_val 2: 0.8
   #> min_val 3: 1.0
   #> max_val 3: 0.0
Screenshot 2023-07-16 at 14 49 14
RWitak commented 1 year ago

You might wanna try passing the min before the max. Not at the computer right now, so can't test it. (I would actually expect you to get an Error "Left Handle value is more than the Right Handle Value, which is not possible." with your input.)

PetervanLunteren commented 1 year ago

@RWitak Thanks for getting back to me. I've tried switching the order of the values, but unfortunately still the same result.

rsl = RangeSliderH(frame, [min_val, max_val], padX=23, digit_precision='.2f')

You would indeed expect a Left Handle value is more than the Right Handle Value, which is not possible. error, but that is not the case. Neither with [min_val, max_val] nor with [max_val, min_val].

PetervanLunteren commented 1 year ago

I created a reprex with the example code from the README.md. In both cases there is no value initialisation and no error saying that the second value is larger than the first one - which makes me suspect that somewhere in the creation of a RangeSlider the values are reset. I've browsed through the code, but could not find anything.

from RangeSlider.RangeSlider import RangeSliderH, RangeSliderV
from tkinter.ttk import *
import tkinter as tk

root = tk.Tk()
hVar1 = tk.DoubleVar(value = 0.2)
hVar2 = tk.DoubleVar(value = 0.8)
print(f"hVar1 before RangeSlider: {hVar1.get()}")
print(f"hVar2 before RangeSlider: {hVar2.get()}")
rs1 = RangeSliderH(root, [hVar1, hVar2], padX=15) # first min, then max. No error.
rs2 = RangeSliderH(root, [hVar2, hVar1], padX=15) # first max, then min. No error.
print(f"hVar1 after RangeSlider:  {hVar1.get()}")
print(f"hVar2 after RangeSlider:  {hVar2.get()}")
rs1.pack()
rs2.pack()

root.mainloop()

Output:

hVar1 before RangeSlider: 0.2
hVar2 before RangeSlider: 0.8
hVar1 after RangeSlider:  1.0
hVar2 after RangeSlider:  0.0
Screenshot 2023-07-16 at 19 34 52
harshvinay752 commented 1 year ago

Hey @PetervanLunteren, please allow some time to check the code. I will go through and update you with the same. Thank you for pointing the error.

harshvinay752 commented 1 year ago

Hey @PetervanLunteren, thank you very much for your patience. I have tried figuring out the bug in code. I have updated the code in repository, you may please use the same. The left handle lower value variable will be followed by right handle higher value variable in the Variables list passed to widget call.

The changes are not in one or two lines, the changes are in various lines including some other fixes, hence I would suggest you to simply replace the RangeSlider.py file with the latest. Kindly update this thread with your feedback.

PetervanLunteren commented 1 year ago

@harshvinay752 Works like a charm! Thanks :) Will this update be published to PyPi too?

harshvinay752 commented 1 year ago

@PetervanLunteren thank you for the feedback. I will update the same to PyPi too, was waiting for resolution to the issue you faced.

harshvinay752 commented 1 year ago

I have updated the same to PyPi too at RangeSlider:PyPi. It can installed using:

Windows: pip install RangeSlider --upgrade

Linux: pip3 install RangeSlider --upgrade