Skip to content

Preprocessed background image

JellyfisHawthorn edited this page Jun 14, 2025 · 1 revision

Default background image and no-gif background image

The default_bg parameter specifies the default background image, the value can be a path or an Image object. The image will be displayed when the GIF is not playing, and the default is the first frame of the GIF.

The nogif_bg parameter specifies background image to be displayed when no GIF is specified.

If both default_bg and nogif_bg are specified, nogif_bg will be used when no GIF is specified, and default_bg will be used when the GIF is specified.

Preprocessed background image

The bg_func parameter allows one or more functions to be used to process the background image

The value of the bg_func parameter is a function (or method) that processes the background image. When called, the Image object of the background image will be passed as a parameter, and the return value should be an Image object.

If the value is None (the default), the background image will not be processed.

The value can also be a sequence of functions (or methods) that process the background image. The background image will be processed by each function (or method) in the sequence.

Some static methods are defined in the module's BgFunc class for handling background images:

  • BgFunc.darken: Darken the image.
  • BgFunc.gif_sign: Add a gray transparent circle in the middle of the image with GIF text.
  • BgFunc.blur: Blur the image.

Example:

case_3.py:

from tkinter import *
from TkGifWidget import *
root = Tk()

# Background images are not processed by default
gif1 = AnimatedGif('../gif/example.gif')
gif1.pack()
# Blur the background image
gif2 = AnimatedGif('../gif/example.gif', bg_func=BgFunc.blur)
gif2.pack()
# Specify the background image and darken it.
gif3 = AnimatedGif('../gif/example.gif', default_bg='example_bg.png', bg_func=(BgFunc.darken))
gif3.pack()
# Add a GIF logo after darkening the background image
gif3 = AnimatedGif('../gif/example.gif', bg_func=(BgFunc.darken, BgFunc.gif_sign))
gif3.pack()

root.mainloop()

Result:

case_3.gif

Clone this wiki locally