Printing to the display

Due to the creative nature of me and a lot of other people, there's many functions to print to the display - but we'll be using just basic text.

Drawing text can be in a terminal way (just add text and the backend will manage text wrapping, coordinates, etc.) or in a low level, pick the coordinates where you want the text to appear way. We'll be using the easiest: the terminal way, in this example.

To start, create the terminal backend class.

terminal = tpil.gui.screenConsole(tpil)

Any ready-made UI functions will be accessible via the GUI sub-class. Unfortunately due to my stupidity you have to pass the tpil argument to the functions in said subclass. Oops.

And to write text to the terminal console,

terminal.addText("hello world")

Our example should now look something like this:

from core.plugin import BasePwnhyvePlugin

class PWNExample(BasePwnhyvePlugin):
    def myExample(tpil):
        terminal = tpil.gui.screenConsole(tpil)
        
        terminal.addText("hello world")
        
        return

Now if you try this code, it should run without errors. But you can't read anything. This is because:

1

The function immediately returns after drawing the text

There's nothing to wait for you to read the text after you wrote to the display, so it'll just immediately exit, clear, and go back to the menu.

So we should wait for our user to press a key this time.

To wait for the user's input, we'd use tpil.waitForKey().

Our code should look like this now:

from core.plugin import BasePwnhyvePlugin

class PWNExample(BasePwnhyvePlugin):
    def myExample(tpil):
        terminal = tpil.gui.screenConsole(tpil)
        terminal.addText("hello world")
        
        tpil.waitForKey()
        
        return

Running this code on the Pi should cause no errors, and should show "hello world" on the display. 🎉

Last updated