Skip to content

BUG(?): Player doesn't play if displaying twice #3967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hai-schrodinger opened this issue Nov 25, 2024 · 3 comments
Open

BUG(?): Player doesn't play if displaying twice #3967

hai-schrodinger opened this issue Nov 25, 2024 · 3 comments

Comments

@hai-schrodinger
Copy link

hai-schrodinger commented Nov 25, 2024

Hi there,

image

Please try above. If display once, the player will play and the slider value keeps changing. If displaying twice and clicking the play button, the slider value only changes once.

@hai-schrodinger hai-schrodinger changed the title Player doesn't play if displaying twice BUG(?): Player doesn't play if displaying twice Nov 25, 2024
@afonit
Copy link

afonit commented Dec 3, 2024

Putting your code here so others can reproduce more quickly - I can confirm the behavior you are seeing.

from ipywidgets import IntSlider, Play
from traitlets import link

player = Play()
slider = IntSlider(max=10, min=0, step=1)
link((player, 'value'), (slider, 'value'))
slider

the behavior also occurs when using observe (not sure if that does the exact same thing as the link you used)

from ipywidgets import IntSlider, Play, HBox
from traitlets import link

player = Play(interval=500)
slider = IntSlider(max=100, min=0, step=1)
# link((player, 'value'), (slider, 'value'))

def on_value_change(change):
    slider.value = change['new']
    # print(change['new'])
    

player.observe(on_value_change, names='value')

# uncomment the below line to see the working model
# HBox([slider, player])

# uncomment the below line to see that when you hit play it only increments once for each time play is clicked
# HBox([slider, player, player])

@asaboor-gh
Copy link

I encountered same issue. Also, if you delete a display of Play widget and display again, it does not play again.

@asaboor-gh
Copy link

asaboor-gh commented Mar 23, 2025

I have created another version of Play widget based on anywidget with the comprehensive help of Microsoft Copilot.
It lets you play/pause as usual but also enables you to pick an arbitrary frame using a slider. The issue of a not playing duplicate display or on re-displaying is apparently solved in this case.

Here is Python and ESM source code for this widget.

from ipywidgets import interact
from ipyslides.utils import AnimationSlider

widget = AnimationSlider(interval=20, nframes=20, continuous_update=False) 

@interact(w=widget)
def animate(w):
    print('w^2 = ', w**2)

widget
20250324-1530-36.2471137.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants