Cardstock: A Simple Python GUI Builder

Cardstock is an Python GUI builder that is focused on making it easy for new Python programmers to create card or form based applications. I was a little sceptical at first but I thought that I’d try using Cardstock with a typical Raspberry Pi project.

This blog shows the steps that I went through to create a Raspberry Pi GUI app that shows BME280 sensor data.

Getting Started

The first step is to install the cardstock Python library and it’s dependencies:

pip3 install cardstock

The biggest difference between cardstock and a typical Python project is that cardstock has a graphic creation environment with an embedded event editor where the Python code is inserted. This means there are no external Python (.py) files, instead the code is embedded within the cardstock (.cds) file.

To start cardstock, at the command line enter: cardstock. The IDE has a left panel for design, and a object configuration panel, and an event code panel.

BME200 Sensor Project

A BME280 Python sensor library in stalled by:

pip3 install bme280pi

For the sensor data, I wanted to have the results shown in vertical bars. My first pass only had 1 bar with a top value, and a bottom label. I used 2 rectangles, an outer for a frame, and a fill inner bar with a height of 200. Once I was happy with the first bar I grouped everything together and then made 2 copies.

After I tweaked each of the objects with an _1, _2 or _3 and I edited the colours and custom descriptions I added the Python code.

By clicking on the card background, the card’s on_setup(self) code window can be accessed.

Python libraries would be typically be defined in the on_setup function.

Rather than putting all the sensor refresh code in the on_setup I created an on_message function. (Use the +Add Event button for this). I would have rather created a custom get_sensor_data() function, unfortunately cardstock didn’t seem to support the creation of custom functions.

Note: Communications between functions is done via messages

To manually refresh the card a Refresh button was added. A button press would issue an on_click event. Like the card on_setup function a: card.send_message(‘refresh’) function is also called to refresh the sensor data.

The running app looked like:

Summary

For new Python coders Cardstock offers a nice easy programming environment. The integration between drawing objects and coding Python event, ties things together cleanly. I believe that this is a great package for kids to learn and play with.

As an experienced user, however, I found that Cardstock was missing a lot of widgets (especially charting, tables, and timers) that I’m used to having.

As a continuation to this project more cards could be added to show historical data and webcam video feed.

Leave a comment