Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

(Python) what does the syntax 'slider.var' mean in this function

I am trying to understanding the following codes

s_time = Slider(ax_time, 'Time', 0, 30, valinit=0)


# if deleting the following part, plot will not move
def update(val):
    pos = s_time.val
    ax.axis([pos, pos+10, 20, 40])
    fig.canvas.draw_idle()
s_time.on_changed(update)

I am confused about

What does ‘s_time.val’ here do? a (slider variable).(input parameter)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks!

>Solution :

s_time is an instance of the Slider class. on_changed is an attribute of the Slider class. In your code, there would be code similar to this –

class Slider:
  ...
  def on_changed(self,update):
    update()
  ...

So when you make a new Slider object in a variable called s_time and call the on_changed function, it will reference the code inside the class.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading