Player#

Download this notebook from GitHub (right-click to download).


import panel as pn

pn.extension()

The Player widget displays media-player-like controls that allow playing and stepping through a range of values. When playing it triggers events at a pre-defined interval on the frontend, advancing the player value each time. It falls into the broad category of single-value slider widgets that provide a compatible API and includes the IntSlider and FloatSlider widgets.

For more information about listening to widget events and laying out widgets refer to the widgets user guide. Alternatively you can learn how to build GUIs by declaring parameters independently of any specific widgets in the param user guide. To express interactivity entirely using Javascript without the need for a Python server take a look at the links user guide.

Parameters:#

For layout and styling related parameters see the customization user guide.

Core#

  • direction (int): Current play direction of the Player (-1: playing in reverse, 0: paused, 1: playing).

  • start (int): The range’s lower bound

  • end (int): The range’s upper bound

  • step (int): The interval between values

  • value (object): The current value; must be one of the option values

Display#

  • disabled (boolean): Whether the widget is editable

  • interval (int): Interval in milliseconds between updates

  • name (str): The title of the widget

  • loop_policy (str): Looping policy; must be one of ‘once’, ‘loop’, or ‘reflect’

  • show_loop_controls (boolean): Whether radio buttons allowing to switch between loop policies options are shown


The widget has a number of buttons to go to the first or last value, step forward or backward, or play and pause the widget. It also provides control over the loop_policy which determines whether to play ‘once’, ‘loop’, or ‘reflect’. Additionally - and + buttons slow down and speed up the player speed.

player = pn.widgets.Player(name='Player', start=0, end=100, value=32, loop_policy='loop')

player

Like most other widgets, Player has a value parameter that can be accessed or set:

player.value
32

The Player can be controlled programmatically using the direction parameter which has three possible states:

  • -1: playing in reverse

  • 0: paused

  • 1: playing

Alternatively it can be controlled via the .play, .pause and .reverse methods:

import time

player.play()
time.sleep(2)
player.reverse()
time.sleep(2)
player.pause()

Controls#

The Player widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:

pn.Row(player.controls(jslink=True), player)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).