Skip to content
Alejandro Autalán edited this page Apr 9, 2022 · 5 revisions

Overview

Pygubu designer now supports to use custom ttk styles defined by the user (Since version 0.23). This is an initial attempt to support ttk styles.

The process to define your custom styles in pygubu-designers is as follows.

Create a style definition file

This is a python file where you will write your styles.

To create a new file:

  • Navigate to Edit > Preferences.
  • Click on Tkk Styles tab, then click 'Create New'
  • Enter the filename to save your styles.
  • Save and close the preferences dialog window.

The style definition file

Open the created file with your favorite editor. This is a regular python file, so use python syntax.

It will contain the following:

  • Description of how to use the file.
  • An example ttk style definition.
# --------------------
# This file is used for defining Ttk styles.
# Use the 'style' object to define styles.

# Pygubu Designer will need to know which style definition file
# you wish to use in your project.

# To specify a style definition file in Pygubu Designer:
# Go to: Edit -> Preferences -> Ttk Styles -> Browse (button)

# In Pygubu Designer:
# Assuming that you have specified a style definition file,
# - Use the 'style' combobox drop-down menu in Pygubu Designer
#   to select a style that you have defined.
# - Changes made to the chosen style definition file will be
#   automatically reflected in Pygubu Designer.
# --------------------

# Example code:
style.configure('MySpecialButton.TButton',
                font=('helvetica', 12, 'bold'),
                background='green', foreground='white')

As you see in the example, you must use the style object to create ttk style definitions. Pygubu Designer will monitor this file and will load the changes automatically.

Style naming

It is recommended that you end your style name with the ttk style class associated to the widget. For example, to create a style for blue Labels:

# the ttk style class for Label is TLabel:
style.configure('MyBlueLabels.TLabel', foreground='blue')

In design time, you will have the style available for select in labels using the style property.

If you do not follow this recommendation, the style will not be available for select, and you will need to input the style name manually to use it.

Clone this wiki locally