DearPyGui
DearPyGui copied to clipboard
Callback not working when used dpg.set_value
Version of Dear PyGui
Version: 1.62 Operating System: Windows 10
My Issue/Question
Callback does not work when the slider value is set via the dpg.set_value function. While if I move the slider with the mouse the callback is executed
To Reproduce
Steps to reproduce the behavior:
- Move Slider and view Terminal value of slider that change
- Press button "Set". Slider move but value in Terminal not showed
Expected behavior
It would be useful if the callback is also executed when the slider (or other widget) is set the value by dpg.set_value
Standalone, minimal, complete and verifiable example
import dearpygui.dearpygui as dpg
from time import sleep
dpg.create_context()
dpg.create_viewport(title='Custom Title', width=800, height=600,x_pos=0,y_pos=0,clear_color=(37,37,38,255))
def GetSliderValue(sender):
print(dpg.get_value(sender))
def Setvalueslider():
for i in range(0,256):
dpg.set_value("Slider",i)
sleep(0.01)
with dpg.window(label="Tutorial", pos=(0, 0), width=500, height=300,no_title_bar=True) as win2:
dpg.add_slider_int(tag="Slider",min_value=0,max_value=255,vertical=True,callback=lambda sender:GetSliderValue(sender))
dpg.add_button(label="Set",callback=lambda:Setvalueslider())
dpg.setup_dearpygui()
dpg.show_viewport(maximized=True)
dpg.start_dearpygui()
dpg.destroy_context()
i could have a workaround thats little bit trashy but if u need it right now u could do it like that:
import dearpygui.dearpygui as dpg
from time import sleep
dpg.create_context()
dpg.create_viewport(title='Custom Title', width=800, height=600,x_pos=0,y_pos=0,clear_color=(37,37,38,255))
def GetSliderValue(sender):
print(dpg.get_value("Slider"))
def Setvalueslider():
for i in range(0,256):
dpg.set_value("Slider",i)
print(dpg.get_value("Slider"))
sleep(0.01)
with dpg.window(label="Tutorial", pos=(0, 0), width=500, height=300,no_title_bar=True) as win2:
dpg.add_slider_int(tag="Slider",min_value=0,max_value=255,vertical=True,callback= GetSliderValue)
dpg.add_button(label="Set",callback=lambda:Setvalueslider())
dpg.setup_dearpygui()
dpg.show_viewport(maximized=True)
dpg.start_dearpygui()
dpg.destroy_context()
Closing the issue given there is a workaround for the issue.