(Python) 这个函数中语法 'slider.var' 是什么意思

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

我正在尝试理解以下代码

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)

我很困惑

这里的's_time.val'是做什么的? a(滑块变量).(输入参数)

谢谢!

s_timeSlider class 的实例。 on_changedSlider class 的属性。在你的代码中,会有类似这样的代码 -

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

因此,当您在名为 s_time 的变量中创建一个新的 Slider 对象并调用 on_changed 函数时,它将引用 class 中的代码。