Skip to main content

A widget that displays GIFs in Tkinter

Project description

TkGifWidget

A widget that displays GIFs in Tkinter.
一个能在Tkinter中显示GIF动图的控件。

GitHub License PyPI - Version dependce

Language


English

Overview

This module provides a widget class called AnimatedGif, which can display GIF animations (including some other formats).

The AnimatedGif widget supports setting the number of loops, the image to be displayed when the animation is not playing, and the callback function to be executed when the animation is completed, etc.

In addition, the AnimatedGif widget supports three playback modes, which are:

  • click: background image is displayed before the animation starts, and the animation is played when clicked, and the background image is displayed again when clicked again.

click

  • display: the animation is played when the AnimatedGif widget is mapped, and the animation is stopped when the widget is unmapped.

display

  • hover: the animation is played when the mouse moves over the AnimatedGif widget, and the animation is stopped when the mouse moves out of the widget.

hover

Installation and Import

Install using pip:

pip install TkGifWidget

Import:

from TkGifWidget import *
# or import TkGifWidget

Usage

example.py:

import tkinter as tk
from TkGifWidget import AnimatedGif
root = tk.Tk()
# Create an AnimatedGif widget, play when displayed
gif = AnimatedGif('../gif/example.gif', play_mode='display')
gif.pack()
root.mainloop()

For more information, please refer to the Wiki:

https://github.com/JellyfisHawthorn/TkGifWidget/wiki/English

Shortcoming

Because of the way Tk loads images, GIF animations with irregular opacity can be slow to load.


简体中文

概述

此模块提供了一个名为AnimatedGif的控件类,用于显示GIF动图(也支持一些其他动图格式)。

动图控件支持设置动图的循环次数、未播放时显示的图片、播放完成后执行的回调函数等等。

此外,动图控件支持三种播放模式,分别是:

  • click(点击):点击前显示背景图,点击后播放动图,再次点击重新显示背景图。

点击

  • display(显示):动图控件被映射时开始播放动图,取消映射时结束播放动图。

显示

  • hover:当鼠标移动到动图控件上时播放动图,移出动图控件结束播放动图。

悬停

安装和导入

使用pip安装:

pip install TkGifWidget

导入方式:

from TkGifWidget import *
# 或者使用import TkGifWidget

使用

example.py

import tkinter as tk
from TkGifWidget import AnimatedGif
root = tk.Tk()
# 创建动图控件,显示时播放
gif = AnimatedGif('../gif/example.gif', play_mode='display')
gif.pack()
root.mainloop()

具体请查看Wiki:https://github.com/JellyfisHawthorn/TkGifWidget/wiki/%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87

Bilibili上的介绍文章(版本较旧):https://www.bilibili.com/read/cv31300353/

缺陷

因为Tk的图像加载方式,极少部分透明度不规则的GIF动图加载速度会极慢。

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

tkgifwidget-0.0.9a1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

tkgifwidget-0.0.9a1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file tkgifwidget-0.0.9a1.tar.gz.

File metadata

  • Download URL: tkgifwidget-0.0.9a1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tkgifwidget-0.0.9a1.tar.gz
Algorithm Hash digest
SHA256 d4c131c65572b6e9efdcad1c8ff4668e073031f95c4ea250700efead83a60d3c
MD5 917bf996df9dd77dbcfaa6185631eb62
BLAKE2b-256 5e0fa887c289a0caa9c89f67b25157f2266a751ddc4b3113a33d9593a2ef609a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tkgifwidget-0.0.9a1.tar.gz:

Publisher: publish.yml on JellyfisHawthorn/TkGifWidget

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

File details

Details for the file tkgifwidget-0.0.9a1-py3-none-any.whl.

File metadata

  • Download URL: tkgifwidget-0.0.9a1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tkgifwidget-0.0.9a1-py3-none-any.whl
Algorithm Hash digest
SHA256 9091009d47d385e1c8e95bba8143908cb361b5ae8198afe6dbee0d2784ceaee0
MD5 2b3ebcdc10e841acee32367b6667842d
BLAKE2b-256 4003db3bcef96bc7464bb49b65a7f2b0c2f1f49acfc5c732d49abc68163f135f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tkgifwidget-0.0.9a1-py3-none-any.whl:

Publisher: publish.yml on JellyfisHawthorn/TkGifWidget

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