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.9a2.tar.gz (11.2 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.9a2-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tkgifwidget-0.0.9a2.tar.gz
  • Upload date:
  • Size: 11.2 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.9a2.tar.gz
Algorithm Hash digest
SHA256 73959c355d1fab04896a7c2ab3ac5c0d52f0942269ee36d65fc0fd31789e8991
MD5 aaebc9c8418b4eab80ce857e64704367
BLAKE2b-256 e1ae4a01f69672922ed1a4760685780d8b6bd3aaefe7142aee648964b0bdcd5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tkgifwidget-0.0.9a2.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.9a2-py3-none-any.whl.

File metadata

  • Download URL: tkgifwidget-0.0.9a2-py3-none-any.whl
  • Upload date:
  • Size: 10.4 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.9a2-py3-none-any.whl
Algorithm Hash digest
SHA256 39ee43aeac6984849df0f473201313c41f4ed4ed96390b798d185910b77c1d85
MD5 82cf21125b7ec222fe547611cb4ef82a
BLAKE2b-256 94efb6d8fe2936e4574552b88effc8c331840b27dd7a015c7e6cf66a7ca8661a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tkgifwidget-0.0.9a2-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