StyleBuilderTK
ttkbootstrap.style.StyleBuilderTK
A class for styling legacy tkinter widgets (not ttk).
The methods in this classed are used internally to update tk widget style configurations and are not intended to be called by the end user.
All legacy tkinter widgets are updated with a callback whenever the theme is changed. The color configuration of the widget is updated to match the current theme. Legacy ttk widgets are not the primary focus of this library, however, an attempt was made to make sure they did not stick out amongst ttk widgets if used.
Some ttk widgets contain legacy components that must be updated such as the Combobox popdown, so this ensures they are styled completely to match the current theme.
colors: Colors
property
readonly
A reference to the Colors
object for the current theme.
is_light_theme: bool
property
readonly
Returns True
if the theme is light, otherwise False
.
theme: ThemeDefinition
property
readonly
A reference to the ThemeDefinition
object for the current
theme.
update_button_style(self, widget)
Update the button style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Button |
The button object to update. |
required |
Source code in ttkbootstrap/style.py
def update_button_style(self, widget: tk.Button):
"""Update the button style.
Parameters:
widget (tkinter.Button):
The button object to update.
"""
background = self.colors.primary
foreground = self.colors.selectfg
activebackground = Colors.update_hsv(self.colors.primary, vd=-0.1)
widget.configure(
background=background,
foreground=foreground,
relief=tk.FLAT,
borderwidth=0,
activebackground=activebackground,
highlightbackground=self.colors.selectfg,
)
update_canvas_style(self, widget)
Update the canvas style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Canvas |
The canvas object to update. |
required |
Source code in ttkbootstrap/style.py
def update_canvas_style(self, widget: tk.Canvas):
"""Update the canvas style.
Parameters:
widget (tkinter.Canvas):
The canvas object to update.
"""
# if self.is_light_theme:
# bordercolor = self.colors.border
# else:
# bordercolor = self.colors.selectbg
widget.configure(
background=self.colors.bg,
highlightthickness=0,
# highlightbackground=bordercolor,
)
update_checkbutton_style(self, widget)
Update the checkbutton style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Checkbutton |
The checkbutton object to update. |
required |
Source code in ttkbootstrap/style.py
def update_checkbutton_style(self, widget: tk.Checkbutton):
"""Update the checkbutton style.
Parameters:
widget (tkinter.Checkbutton):
The checkbutton object to update.
"""
widget.configure(
activebackground=self.colors.bg,
activeforeground=self.colors.primary,
background=self.colors.bg,
foreground=self.colors.fg,
selectcolor=self.colors.bg,
)
update_entry_style(self, widget)
Update the entry style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Entry |
The entry object to update. |
required |
Source code in ttkbootstrap/style.py
def update_entry_style(self, widget: tk.Entry):
"""Update the entry style.
Parameters:
widget (tkinter.Entry):
The entry object to update.
"""
if self.is_light_theme:
bordercolor = self.colors.border
else:
bordercolor = self.colors.selectbg
widget.configure(
relief=tk.FLAT,
highlightthickness=1,
foreground=self.colors.inputfg,
highlightbackground=bordercolor,
highlightcolor=self.colors.primary,
background=self.colors.inputbg,
insertbackground=self.colors.inputfg,
insertwidth=1,
)
update_frame_style(self, widget)
Update the frame style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Frame |
The frame object to update. |
required |
Source code in ttkbootstrap/style.py
def update_frame_style(self, widget: tk.Frame):
"""Update the frame style.
Parameters:
widget (tkinter.Frame):
The frame object to update.
"""
widget.configure(background=self.colors.bg)
update_label_style(self, widget)
Update the label style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Label |
The label object to update. |
required |
Source code in ttkbootstrap/style.py
def update_label_style(self, widget: tk.Label):
"""Update the label style.
Parameters:
widget (tkinter.Label):
The label object to update.
"""
widget.configure(foreground=self.colors.fg, background=self.colors.bg)
update_labelframe_style(self, widget)
Update the labelframe style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.LabelFrame |
The labelframe object to update. |
required |
Source code in ttkbootstrap/style.py
def update_labelframe_style(self, widget: tk.LabelFrame):
"""Update the labelframe style.
Parameters:
widget (tkinter.LabelFrame):
The labelframe object to update.
"""
if self.is_light_theme:
bordercolor = self.colors.border
else:
bordercolor = self.colors.selectbg
widget.configure(
highlightcolor=bordercolor,
foreground=self.colors.fg,
borderwidth=1,
highlightthickness=0,
background=self.colors.bg,
)
update_listbox_style(self, widget)
Update the listbox style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Listbox |
The listbox object to update. |
required |
Source code in ttkbootstrap/style.py
def update_listbox_style(self, widget: tk.Listbox):
"""Update the listbox style.
Parameters:
widget (tkinter.Listbox):
The listbox object to update.
"""
if self.is_light_theme:
bordercolor = self.colors.border
else:
bordercolor = self.colors.selectbg
widget.configure(
foreground=self.colors.inputfg,
background=self.colors.inputbg,
selectbackground=self.colors.selectbg,
selectforeground=self.colors.selectfg,
highlightcolor=self.colors.primary,
highlightbackground=bordercolor,
highlightthickness=1,
activestyle="none",
relief=tk.FLAT,
)
update_menu_style(self, widget)
Update the menu style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Menu |
The menu object to update. |
required |
Source code in ttkbootstrap/style.py
def update_menu_style(self, widget: tk.Menu):
"""Update the menu style.
Parameters:
widget (tkinter.Menu):
The menu object to update.
"""
widget.configure(
tearoff=False,
activebackground=self.colors.selectbg,
activeforeground=self.colors.selectfg,
foreground=self.colors.fg,
selectcolor=self.colors.primary,
background=self.colors.bg,
relief=tk.FLAT,
borderwidth=0,
)
update_menubutton_style(self, widget)
Update the menubutton style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Menubutton |
The menubutton object to update. |
required |
Source code in ttkbootstrap/style.py
def update_menubutton_style(self, widget: tk.Menubutton):
"""Update the menubutton style.
Parameters:
widget (tkinter.Menubutton):
The menubutton object to update.
"""
activebackground = Colors.update_hsv(self.colors.primary, vd=-0.2)
widget.configure(
background=self.colors.primary,
foreground=self.colors.selectfg,
activebackground=activebackground,
activeforeground=self.colors.selectfg,
borderwidth=0,
)
update_radiobutton_style(self, widget)
Update the radiobutton style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Radiobutton |
The radiobutton object to update. |
required |
Source code in ttkbootstrap/style.py
def update_radiobutton_style(self, widget: tk.Radiobutton):
"""Update the radiobutton style.
Parameters:
widget (tkinter.Radiobutton):
The radiobutton object to update.
"""
widget.configure(
activebackground=self.colors.bg,
activeforeground=self.colors.primary,
background=self.colors.bg,
foreground=self.colors.fg,
selectcolor=self.colors.bg,
)
update_scale_style(self, widget)
Update the scale style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.scale |
The scale object to update. |
required |
Source code in ttkbootstrap/style.py
def update_scale_style(self, widget: tk.Scale):
"""Update the scale style.
Parameters:
widget (tkinter.scale):
The scale object to update.
"""
if self.is_light_theme:
bordercolor = self.colors.border
else:
bordercolor = self.colors.selectbg
activecolor = Colors.update_hsv(self.colors.primary, vd=-0.2)
widget.configure(
background=self.colors.primary,
showvalue=False,
sliderrelief=tk.FLAT,
borderwidth=0,
activebackground=activecolor,
highlightthickness=1,
highlightcolor=bordercolor,
highlightbackground=bordercolor,
troughcolor=self.colors.inputbg,
)
update_spinbox_style(self, widget)
Update the spinbox style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Spinbox |
THe spinbox object to update. |
required |
Source code in ttkbootstrap/style.py
def update_spinbox_style(self, widget: tk.Spinbox):
"""Update the spinbox style.
Parameters:
widget (tkinter.Spinbox):
THe spinbox object to update.
"""
if self.is_light_theme:
bordercolor = self.colors.border
else:
bordercolor = self.colors.selectbg
widget.configure(
relief=tk.FLAT,
highlightthickness=1,
foreground=self.colors.inputfg,
highlightbackground=bordercolor,
highlightcolor=self.colors.primary,
background=self.colors.inputbg,
buttonbackground=self.colors.inputbg,
insertbackground=self.colors.inputfg,
insertwidth=1,
# these options should work, but do not have any affect
buttonuprelief=tk.FLAT,
buttondownrelief=tk.SUNKEN,
)
update_text_style(self, widget)
Update the text style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Text |
The text object to update. |
required |
Source code in ttkbootstrap/style.py
def update_text_style(self, widget: tk.Text):
"""Update the text style.
Parameters:
widget (tkinter.Text):
The text object to update.
"""
if self.is_light_theme:
bordercolor = self.colors.border
else:
bordercolor = self.colors.selectbg
focuscolor = widget.cget("highlightbackground")
if focuscolor in ["SystemButtonFace", bordercolor]:
focuscolor = bordercolor
widget.configure(
background=self.colors.inputbg,
foreground=self.colors.inputfg,
highlightcolor=focuscolor,
highlightbackground=bordercolor,
insertbackground=self.colors.inputfg,
selectbackground=self.colors.selectbg,
selectforeground=self.colors.selectfg,
insertwidth=1,
highlightthickness=1,
relief=tk.FLAT,
padx=5,
pady=5,
font="TkDefaultFont",
)
update_tk_style(self, widget)
Update the window style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Tk |
The tk object to update. |
required |
Source code in ttkbootstrap/style.py
def update_tk_style(self, widget: tk.Tk):
"""Update the window style.
Parameters:
widget (tkinter.Tk):
The tk object to update.
"""
widget.configure(background=self.colors.bg)
update_toplevel_style(self, widget)
Update the toplevel style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
tkinter.Toplevel |
The toplevel object to update. |
required |
Source code in ttkbootstrap/style.py
def update_toplevel_style(self, widget: tk.Toplevel):
"""Update the toplevel style.
Parameters:
widget (tkinter.Toplevel):
The toplevel object to update.
"""
widget.configure(background=self.colors.bg)