Skip to content

Bootstrap (Built-in, Core)

ttkbootstrap_icons.bootstrap.BootstrapIcon

Bases: Icon

Convenience icon for the Bootstrap glyph set.

Resolves the provided name (optionally with a style) using BootstrapFontProvider, then initializes the base Icon with the resolved glyph.

Parameters:

Name Type Description Default
name str

Glyph name. May be a friendly name (e.g. "house") or a raw glyph (e.g. "house-fill"). If you pass a conflicting style (e.g. name ends with "-fill" but you set style="outline"), a ValueError is raised.

required
size int

Pixel size of the rasterized image (default: 24).

24
color str

Foreground color used to render the glyph (default: "black").

'black'
style BootstrapStyles | None

Optional style override: "outline" or "fill". If omitted, the provider's default style is used. When name already encodes a style suffix (e.g. "-fill"), that suffix takes precedence.

None

Raises:

Type Description
ValueError

If the name cannot be resolved for the requested style.

__slots__ = ('name', 'size', 'color', '_img', '_font_path', '_icon_set_id') class-attribute instance-attribute

_cache = {} class-attribute

_current_font_path = None class-attribute

_font_cache = {} class-attribute

_font_path = Icon._current_font_path instance-attribute

_fontfile_cache = {} class-attribute

_icon_map = {} class-attribute

_icon_map_cache = {} class-attribute

_icon_set = '' class-attribute

_icon_set_id = Icon._icon_set instance-attribute

_img = self._render() instance-attribute

_initialized = False class-attribute

_is_regenerating = False class-attribute

_original_image = None class-attribute instance-attribute

_render_params_cache = {} class-attribute

_transparent_cache = {} class-attribute

_widget_mappings = {} class-attribute

color = color instance-attribute

image property

name = name instance-attribute

size = size instance-attribute

__init__(name, size=24, color='black', style=None)

__str__()

_button_color_for_state(style, parent_style, state)

Resolve the parent style's foreground color for a given state.

Parameters:

Name Type Description Default
style Style

ttk Style instance.

required
parent_style str

Parent style name (e.g., 'my.TButton').

required
state str

State flag to resolve (e.g., 'hover').

required

Returns:

Type Description
Optional[str]

The resolved color string or None if not available.

_configure(font_path, icon_map) classmethod

_ensure_original_image()

Ensure the untinted base image is cached for the '' fallback.

Notes

Uses the instance's own .image to avoid re-instantiation or recursion during host initialization.

_get_transparent(size) classmethod

_on_theme_changed(event) classmethod

Handle <> event by regenerating all mapped icons.

_parse_statespec(style, parent_style, statespec)

Parse the state spec into (state, icon_name, color) triples.

If statespec is not provided, triples are derived from the parent's foreground map using the base icon.

Parameters:

Name Type Description Default
style Style

ttk Style instance.

required
parent_style str

Parent style name to read maps from.

required
statespec Optional[list[IconStateSpec]]

Optional list describing per-state overrides. Each item is a (state, spec) pair where spec is either a color string or a dict with keys name and/or color.

required

Returns:

Type Description
list[tuple[str, str, Optional[str]]]

A list of triples (state, icon_name, color_or_None). If color is

list[tuple[str, str, Optional[str]]]

None, the caller will resolve to the parent's state foreground.

_render()

Render the icon as a PhotoImage, using PIL and caching the result.

_render_icon(name, size, color)

Render a Tk-compatible image for (name, size, color).

By default, this constructs a new instance of type(self) with the provided (name, size, color) and returns its .image. If your host class requires a different constructor or you want a more direct path, override this method.

Parameters:

Name Type Description Default
name str

Icon name to render.

required
size int

Icon size in pixels.

required
color Optional[str]

Optional color to tint the icon. If None, render untinted.

required

Returns:

Type Description
object

A Tk-compatible image object (e.g., PhotoImage).

_slug(token) staticmethod

Return a style-safe token by replacing unsupported characters.

Parameters:

Name Type Description Default
token str

Arbitrary token (e.g., icon name).

required

Returns:

Type Description
str

A string containing only alphanumerics, '-' or '_'.

_state_tuple(state) staticmethod

Convert a state string into a ttk lookup tuple.

Parameters:

Name Type Description Default
state str

Single state flag (e.g., 'hover', 'pressed').

required

Returns:

Type Description
tuple[str, ...]

A one-element tuple containing state.

cleanup() classmethod

Remove all temporary font files and reset internal icon state.

initialize_with_provider(provider, style=None) classmethod

Initialize icon rendering using an external provider.

map(widget, *, subclass=None, statespec=None, mode='merge')

Apply per-state images to a child style derived from the widget's style.

This computes per-state images from statespec (or the parent's foreground map when statespec is omitted), generates a child style name, and maps the image option accordingly. The empty-state ('') fallback is always set to the instance's original untinted image.

Parameters:

Name Type Description Default
widget Widget

ttk widget to style (e.g., ttk.Button).

required
subclass Optional[str]

Optional child style prefix. If omitted, the name is generated by concatenating the unique icon names used (including the base) and appending the size, e.g., "house-house-fill-16.my.TButton".

None
statespec Optional[list[IconStateSpec]]

Optional list of per-state overrides. Each item is a (state, spec) pair where spec is a color string or a dict with name and/or color. If color is omitted, the icon color follows the parent's foreground for that state.

None
mode StateMapMode

Merge strategy for the child style's image map. * "merge" (default): Read the existing image map for the same child style, overwrite incoming states, preserve order of existing entries, and append new states. * "replace": Ignore any existing map and apply only the provided states (plus the fallback).

'merge'

Returns:

Type Description
None

None

ttkbootstrap_icons.bootstrap.BootstrapFontProvider

Bases: BaseFontProvider

Provider for the Bootstrap Icons dataset.

Bootstrap ships two styles - "outline" and "fill" - encoded by the presence of a "-fill" suffix in the raw glyph name. Both styles share the same font file and are separated via a predicate per style.

Attributes:

Name Type Description
name str

Provider identifier ("bootstrap").

display_name str

Human-friendly name ("Bootstrap").

default_style Optional[str]

Default style ("outline").

styles Optional[str]

Map of style -> {filename, predicate}.

__slots__ = ('_name', '_package', '_display_name', '_filename', '_homepage', '_license_url', '_default_style', '_styles', '_styles_view', '_name_lookup', '_pad_factor', '_y_bias', '_scale_to_fit', '_icon_version') class-attribute instance-attribute

_default_style = kwargs.get('default_style') instance-attribute

_display_name = kwargs.get('display_name', self._name) instance-attribute

_filename = kwargs.get('filename') instance-attribute

_font_bytes_cache_global = {} class-attribute

_glyphmap_cache_global = {} class-attribute

_homepage = kwargs.get('homepage') instance-attribute

_icon_version = kwargs.get('icon_version') instance-attribute

_license_url = kwargs.get('license_url') instance-attribute

_name = kwargs.get('name') instance-attribute

_name_lookup = self.build_name_lookup() instance-attribute

_name_lookup_global = {} class-attribute

_package = kwargs.get('package') instance-attribute

_pad_factor = kwargs.get('pad_factor', 0.1) instance-attribute

_scale_to_fit = kwargs.get('scale_to_fit', True) instance-attribute

_styles = deepcopy(kwargs.get('styles', {})) instance-attribute

_styles_view = MappingProxyType(self._styles) instance-attribute

_y_bias = kwargs.get('y_bias', 0.0) instance-attribute

default_style property

display_name property

font_filename property

has_styles property

Return True if this provider defines styles.

homepage property

icon_version property

license_url property

name property

package property

pad_factor property

Padding factor for icon rendering (0.0-1.0).

scale_to_fit property

Whether to scale down glyphs that exceed the available space.

style_list property

style_map property

uses_single_file property

y_bias property

Vertical bias adjustment for icon rendering.

__init__()

Initialize the provider with style configuration.

Uses a single font file (bootstrap.ttf) for both styles. Style selection is performed by predicates that test for the -fill suffix.

Note

The provider expects glyphmaps named glyphmap.json (single-file) or glyphmap-<style>.json when styles require separate maps.

_is_fill_style(name) staticmethod

_is_outline_style(name) staticmethod

_read_glyphmap_for_style(style)

build_display_index()

build_name_lookup()

format_glyph_name(glyph_name) staticmethod

get_icons_names_for_display()

load_assets(style=None)

resolve_icon_name(name, style=None)

Resolve a user-supplied icon name to the actual glyph name.

Rules: - If style is explicitly provided, we resolve within that style only. If the name clearly encodes a conflicting style suffix (e.g., "-fill" vs requested "outline"), a ValueError is raised. - If style is not provided, infer the style from a "-