From c5254dffb6fd8c8c11205649e680fac638593931 Mon Sep 17 00:00:00 2001 From: my1e5 <10064103+my1e5@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:53:54 +0000 Subject: [PATCH] added slider with step size example --- buttons/slider_with_step_size.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 buttons/slider_with_step_size.py diff --git a/buttons/slider_with_step_size.py b/buttons/slider_with_step_size.py new file mode 100644 index 0000000..50f807b --- /dev/null +++ b/buttons/slider_with_step_size.py @@ -0,0 +1,27 @@ +# Credit @Quattro https://discord.com/channels/736279277242417272/1080603804812181605/1080603804812181605 +import dearpygui.dearpygui as dpg +dpg.create_context() + +"""As a workaround, using format="" you can disable the text in the slider, +then you can add your own label next to the slider, +and change the value according to the step value. +""" + +STEP_SIZE = 2 + +with dpg.window(): + dpg.add_slider_int( + tag="myslider", + label=2*STEP_SIZE, + default_value=2, + min_value=0, + max_value=5, + format="", + callback=lambda s, d: dpg.configure_item("myslider", label=d * STEP_SIZE), + ) + +dpg.create_viewport(title="Slider with step size", width=400, height=400) +dpg.setup_dearpygui() +dpg.show_viewport() +dpg.start_dearpygui() +dpg.destroy_context() \ No newline at end of file