FontDialog
ttkbootstrap.dialogs.dialogs.FontDialog (Dialog)
A dialog that displays a variety of options for choosing a font.
This dialog constructs and returns a Font
object based on the
options selected by the user. The initial font is based on OS
settings and will vary.
The font object is returned when the Ok button is pressed and can be passed to any widget that accepts a font configuration option.
create_body(self, master)
Create the dialog body.
This method should be overridden and is called by the build
method. Set the self._initial_focus
for the widget that
should receive the initial focus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
master |
Widget |
The parent widget. |
required |
Source code in ttkbootstrap/dialogs/dialogs.py
def create_body(self, master):
width = utility.scale_size(master, 600)
height = utility.scale_size(master, 500)
self._toplevel.geometry(f"{width}x{height}")
family_size_frame = ttk.Frame(master, padding=10)
family_size_frame.pack(fill=X, anchor=N)
self._initial_focus = self._font_families_selector(family_size_frame)
self._font_size_selector(family_size_frame)
self._font_options_selectors(master, padding=10)
self._font_preview(master, padding=10)
create_buttonbox(self, master)
Create the dialog button box.
This method should be overridden and is called by the build
method. Set the self._initial_focus
for the button that
should receive the intial focus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
master |
Widget |
The parent widget. |
required |
Source code in ttkbootstrap/dialogs/dialogs.py
def create_buttonbox(self, master):
container = ttk.Frame(master, padding=(5, 10))
container.pack(fill=X)
ok_btn = ttk.Button(
master=container,
bootstyle="primary",
text=MessageCatalog.translate("OK"),
command=self._on_submit,
)
ok_btn.pack(side=RIGHT, padx=5)
ok_btn.bind("<Return>", lambda _: ok_btn.invoke())
cancel_btn = ttk.Button(
master=container,
bootstyle="secondary",
text=MessageCatalog.translate("Cancel"),
command=self._on_cancel,
)
cancel_btn.pack(side=RIGHT, padx=5)
cancel_btn.bind("<Return>", lambda _: cancel_btn.invoke())