Skip to main content

A simple video player widget for Tkinter.

Project description

tkinter-videoplayer

A simple video player component for Tkinter, built with OpenCV and Pillow.

The current alternatives either didn't work (outdated dependencies) or used av (which requires compilation).

Features

  • Batteries included: Includes controls to play, pause, stop, and seek video files
  • Familiar UI: Toggle play/pause with a button or click or spacebar
  • Easy to install: Doesn't use av (which requires compilation on the host system)
  • Looks decent visually, and can be customized in theme.py
  • Works by rendering frames using OpenCV and Pillow

Screenshot

screenshot

Installation

  1. Install dependencies:
    pip install -r requirements.txt
    
  2. Import the component in your Tkinter project.

Quick Start

from tkinter_videoplayer import VideoPlayer
import tkinter as tk

root = tk.Tk()
player = VideoPlayer(root, video_path='sample.mp4', height=360)
root.mainloop()

API

VideoPlayer(parent, video_path, **options)

  • parent: Tkinter parent widget
  • video_path: Path to the video file
  • **options: Additional options to customize the player:
    • autoplay (bool): Start playback automatically when loaded. Default: False.
    • loop (bool): Loop the video when it reaches the end. Default: False.
    • controls (bool): Show playback controls (play, pause, seek, etc.). Default: True.
    • width (int): Width of the video player in pixels. Default: video width or parent width.
    • height (int): Height of the video player in pixels. Default: video height or parent height.

You can also edit the default theme by modifying theme.py.

Methods

  • play(): Start or resume playback
  • pause(): Pause playback
  • stop(): Stop playback and reset

Properties

  • autoplay (bool): Whether playback starts automatically when loaded.
  • loop (bool): Whether playback loops when the video ends.
  • controls (bool): Whether playback controls are shown.
  • currentTime (float): Current playback time in seconds (get/set).
  • duration (float): Duration of the loaded video in seconds (read-only).

Events

  • play: Called when playback starts
  • pause: Called when playback pauses
  • ended: Called when playback ends
  • load: Called when the video loads

Usage Example

See the examples folder for more examples!

  • 01_combined_examples.py: Shows four different video player configurations in a single 2x2 grid window, each with a title, video, and code snippet.
  • 02_events.py: Demonstrates how to use event listeners for play, pause, and end events.
  • 03_external_controls.py: Shows how to control the video player externally with custom buttons.
# Example: Basic usage
from tkinter_videoplayer import VideoPlayer
import tkinter as tk

root = tk.Tk()
player = VideoPlayer(root, video_path='sample.mp4', height=360)
player.frame.pack()
root.mainloop()
# Example: Adding event listeners (see 02_events.py)
def handle_play():
    print("Video started!")
def handle_pause():
    print("Video paused.")
def handle_ended():
    print("Video ended.")

player.add_event_listener("play", handle_play)
player.add_event_listener("pause", handle_pause)
player.add_event_listener("ended", handle_ended)
# Example: External controls (see 03_external_controls.py)
btn_play = tk.Button(root, text="Play", command=player.play)
btn_pause = tk.Button(root, text="Pause", command=player.pause)
btn_stop = tk.Button(root, text="Stop", command=player.stop)
btn_play.pack()
btn_pause.pack()
btn_stop.pack()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tkinter_videoplayer-1.0.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tkinter_videoplayer-1.0.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file tkinter_videoplayer-1.0.0.tar.gz.

File metadata

  • Download URL: tkinter_videoplayer-1.0.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tkinter_videoplayer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f380631efd4740b05c967d1d085e3fb6adc66ebba815aabd9ba0cbc0cfe8fca6
MD5 ccc685772571f2b5ead8536de8a080ec
BLAKE2b-256 6a1a8bf46f8ebd2c2164f281ddda052dac45dc2602f700e872694bebdd987e48

See more details on using hashes here.

Provenance

The following attestation bundles were made for tkinter_videoplayer-1.0.0.tar.gz:

Publisher: publish_to_pypi.yml on cmdr2/tkinter-videoplayer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tkinter_videoplayer-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tkinter_videoplayer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e07ce723d9afe87956fc463637b660a78103807abddbfb0a2b577830c90f84b
MD5 fa305614bb1b845cb0cf44a62f646622
BLAKE2b-256 ba655648cc03934f32ef4e909dcbaca9380c9e9b29440dee9392a94e736f911b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tkinter_videoplayer-1.0.0-py3-none-any.whl:

Publisher: publish_to_pypi.yml on cmdr2/tkinter-videoplayer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page