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)
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:
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