How to use slider to update the image real-time?

OS (e.g. Win10): 14.1.2 (23B92)
PsychoPy version (e.g. 1.84.x): 2023.2.2
Standard Standalone? (y/n) If not then what?:y
What are you trying to achieve?:
I am using Slider component, a image and a code component in one trial. Here, I want to update the image (the image are from a folder, and the image format is like butter_melt0012.jpg) on the screen according to participants’ slider rating.

What did you try to make it work?:
This is my code in begin routine and each frame.

def pad_with_zeros(number, width):
    num_str = str(number)
    padding = width - len(num_str)
    return '0' * padding + num_str

slider_choice = slider.getRating()

if slider_choice == None:
    slider_choice= 120    
print(slider_choice)
num_str = pad_with_zeros(slider_choice, 4)

thisImage = 'stimuli/jpg_frames/'+thisTrial['ImagePath']+'/'+thisTrial['ImagePath']+num_str+'.jpg'

What specifically went wrong when you tried that?:
When I tried the code, the screen shows the slider, and only one image, but the image won’t update if i move the slider and it crashed. How can I make sure slider.getRating() doesn’t return NONE but a number? Thanks for the help!!

How about

if slider.getRating():
     slider_choice = slider.getRating()
else:
    slider_choice= 120    
print(slider_choice)
num_str = pad_with_zeros(slider_choice, 4)

Hi, thank you!
I tried it, but there is only picture showing on the screen and then disappeared. The screen freezes and no slider shows up. What should I do about it?

I think the code basically just shows the image (frame number =120) for 1 s.