Source code for ccu.fancyplots._gui.utils

"""GUI utility functions.

Specifically, this module provides :func:`ccu.fancyplots._gui.utils.open_image`,
which opens a Tkinter-compatible version of an image shipped with
:mod:`ccu`, and :func:`ccu.fancyplots._gui.utils.print_easter_egg`, which prints
an Easter egg.
"""

import importlib

from PIL import Image
from PIL import ImageTk

from ccu.__about__ import __version__

_EASTER_EGG_WIDTH = 103


[docs] def open_image(name: str, width: int, height: int) -> ImageTk.PhotoImage: """Open Tkinter-compatible version of a ``ccu`` image. Args: name: The name of the image to open. width: The width of the image when opened. height: The height of the image when opened. Returns: A Tkinter-compatible version of the opened image. """ images_ = importlib.resources.files("ccu.fancyplots.images") image = Image.open(images_.joinpath(name)) resized_image = image.resize((width, height), Image.LANCZOS) tk_image = ImageTk.PhotoImage(resized_image) return tk_image