The adafruit_progressbar library makes it easy to create and display progress bars. The code initializes a ProgressBar with a size, location, and some colors. To change the bar, set the progress property, after that, refresh the display so the MagTag will show the updated bar.

These colors can be used to show the 4 available colors on the MagTag screen: 0x000000, 0x666666, 0x999999, 0xFFFFFF.

Simpletest Example

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

Basic progressbar example script
adapted for use on MagTag.
import time
import board
import displayio
import digitalio
from adafruit_progressbar import ProgressBar

# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
display = board.DISPLAY

# a button will be used to advance the progress
a_btn = digitalio.DigitalInOut(board.BUTTON_A)
a_btn.direction = digitalio.Direction.INPUT
a_btn.pull = digitalio.Pull.UP

# Make the display context
splash = displayio.Group(max_size=10)

# set progress bar width and height relative to board's display
BAR_WIDTH = display.width - 40

x = display.width // 2 - BAR_WIDTH // 2
y = display.height // 3

# Create a new progress_bar object at (x, y)
progress_bar = ProgressBar(
    x, y, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x666666, outline_color=0xFFFFFF

# Append progress_bar to the splash group

current_progress = (time.monotonic() % 101) / 100.0
progress_bar.progress = current_progress

# refresh the display

prev_a = a_btn.value
while True:
    cur_a = a_btn.value
    # if a_btn was just pressed down
    if not cur_a and prev_a:
        current_progress += 0.20
        if current_progress > 1.0:
            current_progress = 0.0
        progress_bar.progress = current_progress


    prev_a = cur_a

Now to pull some data from the internet and populate the progress bar with it.

This guide was first published on Dec 02, 2020. It was last updated on Dec 02, 2020.

This page (ProgressBar Basics) was last updated on Apr 14, 2021.

Text editor powered by tinymce.