Use an Android smartphone as a Raspberry Pi screen

Event Processing

The button methods retrieve system information and write the results to the text field. However, this cannot happen directly because the application "freezes" while the method is running. MainLoop() cannot respond to interface events (move window, press button, etc.) during this time.

The button method on_uptime() starting in line 74 thus only starts a thread, and the actual work is then handled asynchronously in get_uptime() (starting in line 90).

As usual with all graphical libraries, only the main thread (MainLoop()) can update the interface. Therefore, the thread creates and sends a self-defined event at the end (line 100). This private event, which I dub SysCmdFinishEvent(), contains only the text to be displayed; the definition is at the beginning of the listing.

The program also binds a method to this event (line 31) in the constructor of AppFrame. A text field is updated here (starting in line 81), and thus the circle closes.

If you want to fill a field automatically with status information, you can use the same approach. A thread running for a long time simply sends an update event with the new field content at fixed intervals.


The program still has two problems: If it starts when the X server is not (yet) running, it crashes, and it stops as soon as the X server app stops running or is out of range.

You can solve the first problem by testing for the X server at program launch and then only continuing the program if there is a response (the code is missing from Listing 1 because of a lack of space). As soon as the app starts, the interface pops up. This only works if you don't use multiple Raspberry Pis on one smartphone.

The system daemon solves the second problem for you. You can start the program as a service with the wxvlcd.service file (Listing 2), which is also where you set the DISPLAY variable. The only special thing about the unit definition is line 10 with the Restart=always statement. It ensures that systemd automatically restarts the program after it has ended. Details and alternatives to always (e.g., on-failure) can be found with the man systemd.service command.

Listing 2




Thanks to the X server and wxPython, you can implement simple control and info displays for your Rasp Pi projects with minimal effort – and all communication is wireless.

If you do not have an Android device or would rather use one of the small 3.2-inch displays with the Raspberry Pi, you can still use wxPython. The program evaluates the DISPLAY variable, so the program can be output locally or over the network, depending on the configuration.

The mature development stage of wxPython offers another benefit. The toolkit is extremely stable, and you will find a sample solution for almost every need online. Even if you have never programmed a graphical user interface before, you will quickly turn out an attractive GUI just by following the example in this article.

The Author

Bernhard Bablok ( is an SAP-HR developer at Allianz Technology SE. When he's not listening to music, riding his bike, or walking, he focuses on Linux, programming, and small computers.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Python’s Tkinter Library

    Use Tkinter to control your Rasp Pi projects from a smartphone or tablet.

  • Python IDEs

    A number of useful development environments are available for Python in Linux. We’ll show you around some popular Python IDEs that are more than just text editors.

  • VS Code for Rasp Pi

    Professional and casual Python developers save time and keystrokes in a Visual Studio Code development environment for remote coding of a Raspberry Pi.

  • ioBroker + Rasp Pi

    Control devices from different manufacturers of home automation devices from a single interface by combining free software and a Raspberry Pi.

  • Deluxe Web Radio

    An LCD in an unusual format, a self-designed housing, and matching software make a simple Raspberry Pi web radio the perfect centerpiece for any living room.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs