The first thing we did was create the badge background.

pybadger.badge_background(background_color=pybadger.WHITE,
                          rectangle_color=pybadger.PURPLE,
                          rectangle_drop=0.2, rectangle_height=0.6)

There are four aspects of the badge background you can customise:

  • background_color: The color that fills the background on the display. Expects a tuple (e.g. (r, g, b)) or a pybadger.COLOR. Defaults to white. Check out the PyBadger Colors page for a list of available colors.
  • rectangle_color: The color of a rectangle color-block that displays over the background. Expects a tuple (e.g. (r, g, b)) or a pybadger.COLOR. Defaults to red. Check out the PyBadger Colors page for a list of available colors.
  • rectangle_drop: The distance from the top of the display that the rectangle begins. This expects a decimal number between 0 and 1 representing a percentage of the display, e.g. 0.2 means the rectangle will begin at a point 20% of the display height from the top of the display. Defaults to 0.4.
  • rectangle_height: The height of the rectangle. This expects a decimal number between 0 and 1 representing a percentage of the display, e.g. 0.4 means the rectangle height will be 40% of the display. Defaults to 0.5.

The rectangle_drop and rectangle_height values are used to place the color-block rectangle on the display by using a decimal number (known as a float in Python) between 0 and 1 representing 0% to 100%. You specify the rectangle_drop to determine how far from the top the rectangle is located. That percentage of the display is filled with the background color above the rectangle. You specify the rectangle_height to determine its height. The remaining percentage of the display is background color shown below the rectangle. In our example, we set rectangle_height to 0.2 meaning 20%, and rectangle_height to 0.6 meaning 60%. 60% + 20% is 80%, leaving 20% left to display below the rectangle, resulting in it being centered vertically on the display.

If you would rather have the badge background be a single color, set rectangle_color to the desired color, rectangle_drop=0, and rectangle_height=1. This will make the background a single color.

This guide was first published on Mar 04, 2020. It was last updated on Mar 04, 2020.

This page (Badge Background) was last updated on Aug 02, 2021.

Text editor powered by tinymce.