2

I need some way to display a decimal value above my slider in PySimpleGUI.

I have already tried putting decimal values, but it throws an error when I do that.

import PySimpleGUI as sg

layout = [sg.Slider(range=(850,999), default_value=997, size=(40,15), orientation='horizontal')]

I want it to display decimal values when sliding through the range, but right now all it does is put it as 850 or 999, instead of 85.0 and 99.9.

Robert B
  • 23
  • 1
  • 3

1 Answers1

2

Sure, you just need to define your range to be 85 to 99 and set a resolution of .1

layout = [[sg.Slider(range=(85.0,99.9), default_value=99.7, resolution=.1, size=(40,15), orientation='horizontal')]]

It's discussed in the docs here: https://pysimplegui.readthedocs.io/en/latest/#slider-element

The docstrings, shown in your IDE, also show that the range can be float and lists the other value as potentially being float as well. If they don't show up in your IDE, use Python's help system

python
Python 3.6.2 |Anaconda, Inc.| (default, Sep 19 2017, 08:03:39) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PySimpleGUI as sg
>>> help(sg.Slider)
Help on class Slider in module PySimpleGUI:

class Slider(Element)
 |  A slider, horizontal or vertical
 |
 |  Method resolution order:
 |      Slider
 |      Element
 |      builtins.object
 |
 |  Methods defined here:
 |

... removed a couple of methods to show just the init method

 |
 |  __init__(self, range=(None, None), default_value=None, resolution=None, tick_interval=None, orientation=None, disable_number_display=False, border_width=None, relief=None, change_submits=False, enable_events=False, disabled=False, size=(None, None), font=None, background_color=None, text_color=None, key=None, pad=None, tooltip=None, visible=True)
 |      :param range: Union[Tuple[int, int], Tuple[float, float]] slider's range (min value, max value)
 |      :param default_value: Union[int, float] starting value for the slider
 |      :param resolution: Union[int, float] the smallest amount the slider can be moved
 |      :param tick_interval: Union[int, float] how often a visible tick should be shown next to slider
 |      :param orientation: (str) 'horizontal' or 'vertical' ('h' or 'v' also work)
 |      :param disable_number_display: (bool) if True no number will be displayed by the Slider Element
 |      :param border_width: (int) width of border around element in pixels
Mike from PSG
  • 5,312
  • 21
  • 39