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.6.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.6-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file tkgifwidget-0.0.6.tar.gz.

File metadata

  • Download URL: tkgifwidget-0.0.6.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.6.tar.gz
Algorithm Hash digest
SHA256 db1b03051ac713122bde86d778fb1245ad1be1d810b2ab89e31a02235826761a
MD5 5798e886e337a7ade546a69b3051d898
BLAKE2b-256 5464f620e71772520d6869641fcaffcf6dd73f4ad996330ddadb5d60d123cbcc

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: tkgifwidget-0.0.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e2696799cd8c2d0e6906289a2e0df8ff8ee5a5c010d045fa05187dbd89a92a49
MD5 c869b691919c16e5768b5b1fb9def2b2
BLAKE2b-256 9da287ed9bbdecd20994c90b78fea2fb098f98f311a85ae07a9b221adadad3d5

See more details on using hashes here.

Provenance

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