Skip to main content

preview projects using the ST7789 display in a tkinter window

Project description

tkst

About

Preview projects using the ST7789 spi display (and corresponding python library) on your desktop with tkinter. Read more here.

jump to...

Doc

Display

  • tkst.Display(displayType)

    main class that provides methods for interacting with a display

    parameters

    methods

    • tkst.Display().start()

      starts the display. For tkst.TK displays it calls tkinter's mainloop() function, and for tkst.ST it calls ST7789's begin() function. Since mainloop() is blocking, tkst.Display().start() will block regardless of display type to ensure code works with either.
    • tkst.Display().awaitStart()

      blocks until tkst.Display().start() has started the display. This is likely unnecessary, as the display starts very quickly, however if you receive a tkst.DisplayError when first calling tkst.Display().display(), then it might be a good idea to use this.
    • tkst.Display().stop()

      stops the display. Any attempts to update the display after calling tkst.Display().stop() will result in a tkst.DisplayError.
    • tkst.Display().display(image)

      display a PIL.Image image on the display.

    properties

    • tkst().Display().output

      a tkst display type (tkst.ST or tkst.TK).
    • tkst().Display().width

      the width of the display (240px).
    • tkst().Display().hegiht

      the height of the display (240px).
    • tkst().Display().isRunning

      a boolean describing whether the display is currently running or not.
    • tkst().Display().root

      the root window on which any image is drawn. It is of type tkinter.Tk() window if tkst().Display().output is tkst.TK, or ST7789.ST7789() if tkst().Display().output is tkst.ST.

Display Types

  • tkst.ST

    display type corresponding to a physical ST7789 display. Requires the ST7789 module to be installed; if it is not, a tkst.DisplayError will be raised.

  • tkst.TK

    display type corresponding to a tkinter window. Requires the tkinter module to be installed; if it is not, a tkst.DisplayError will be raised.

Errors

Usage

  • Firstly import the tkst module (you'll also want to use Pillow and threading)
import tkst
from PIL import Image, ImageDraw, ImageFont
from threading import Thread
  • Define a function to be the target of the thread we're going to create
def updateDisplay(display):
    display.awaitStart()
    img = Image.new('RGB', (display.width, display.height), color=(0, 0, 0)) # the image we're going to display
    draw = ImageDraw.Draw(img) # a way for us to add text etc on top of the image
    draw.text((0,0), "hello, world!", font="/usr/share/fonts/gnu-free/FreeMono.otf", fill=(255, 255, 255)) # add some sample text to our image
    display.display(img) # show this image on the display
  • Set up a main function where we initialise the display and set everything going
def __main__():
    d = tkst.Display(tkst.TK) # just change tkst.TK to tkst.ST when you want to display it on the ST7789
    t = Thread(target=updateDisplay, args=[d,]) # thread to set the picture on the display, has to be threaded as tkst.Display().start() is blocking
    t.start() # start the updater thread
    d.start() # start the display

if __name__ == "__main__": # fancy way of starting the main function
    __main__()
  • Et vóila! That's your first program that you can easily test on your computer before displaying it on an ST7789.

Examples

Check out a couple of examples on my github repo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tkst-0.1.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tkst-0.1.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file tkst-0.1.2.tar.gz.

File metadata

  • Download URL: tkst-0.1.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for tkst-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4fb9120013e0a11c8710bbaad08b401613baeba349f4be9d5f86ca1128c828e3
MD5 377ad73ff4ead82ab2039047c3b223e3
BLAKE2b-256 2ca02898853b0bc99cc89206b64583b63f3e0470af43e7fec15460475856babb

See more details on using hashes here.

File details

Details for the file tkst-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: tkst-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for tkst-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5441d4e13ac4c4ebf3887780944d7133651793c3bed8e9d8a477c7be3dd7f5e8
MD5 0aca8d2361da8445de7350cc1543f030
BLAKE2b-256 4270f132c82cf202e97cc89a940177e62617b63b951ab41d7c427b53a5c1e8ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page