Wiki Raspberry Python GUI

HAMKit Wiki Repository
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
 HAMKit Wiki
News and Information
RasDuinoHat
Raspberry Pi
Standard Page
VDAS
VMAC PiHat v1
VMAC PiHat v2

Having touched on Python and various VMAC PiHat code examples, which can be used to bring the board to life, we are now able to delve a little deeper in order to add more functionality to our code.

The VMAC PiHat code examples are in essence a small script that runs on the Raspberry Pi and then automatically loops while checking for Squelch input signals or DTMF etc.  What would be great, is to allow user input through a graphical user interface (GUI), in order to make our projects even more exciting.

Python itself is textual based, so to add a GUI, we need to look at adding a simple graphical interface such as a button or slider, which can send or receive VMAC PiHat commands or controls.

As with a plethora of Python IDE or editors, offering a range of features but also complexity of use, we also see a number of Python GUI’s that in simple terms, sit on top of Python to give us graphical control.  This article is not about turning you into a Python expert but instead, providing an insight to creating a simple application which hopefully will set the seed to greater things.  Less frustration = increased interest to learn and experiment!

Two such Python GUIs which are easy to use are GUIZero and appJar, we will be exploring using the latter as its simple but powerful, ideal for our projects!  Useful appJar videos here.

It would be assumed that you are going to create some application on your computer and save on the Raspberry Pi.  You could, of course, just work and develop on the Pi itself.

Computer Shopping List

  • Python v3 (Download and install from www.python.org example python-3.6.4)
  • appJar GUI (Install by simply opening a DOS window and enter: pip3 install appjar)
    • If this does not work, you may need to reboot PC, after installing Python
  • Thonny IDE Editor (Download and install from thonny.org)

Note: To allow Thonny to correctly execute GUI code, you may need to make a simple change to the options.  Tools > Options > Interpreter > Python (C:…)  This means you can test GUI code just by pressing F5 (without having to install anything else)

 

Raspberry Pi Shopping List

  • Raspbian (Download desktop image and save to a card raspberrypi.org)
  • Python v3 (Already installed)
  • appJar GUI (Install by simply opening terminal  window and enter: pip3 install appjar)
  • appJar GUI (Install by simply opening terminal  window and enter: pip install appjar)
  • Thonny IDE (Already installed)

That’s it!, you are now well on the way to creating a small application to control the VMAC PiHat.

The below example code will work on your PC and Raspberry Pi.  

First we create a simple graphic window with a button.  Pressing a button will display details in the IDE debug window.

# HAMKit PythonGUI-Code1.py
# GUI Test Code
# Dave Williams G8PUO, January 2018

# Import the GUI library
from appJar import gui

# Create and setup a simple window
app = gui("HAMKit Test Window", "378x265")
app.setBg("lightblue")
app.setFont(16)
app.setTitle("HAMKit - Hello World!")

#Define Button Function
def press(btn):
	print(btn)

# Buttons
app.addButton("One", press)
app.addButton("Two", press)
app.addButton("Three", press)

# Start the GUI
app.go()

Example of code running on a PC

Example same code running on the Raspberry Pi

As you can see, this enables us to make quick applications for the Raspberry Pi.  As this is a Python script, you can very easily run this from the Terminal Window too.

These Wiki pages are extended to include GUI in the Wiki VMAC PiHat Matrix GUI

Other examples of appJar code can be found here.


Please feel free to share our product love through the below

HAMKit | Facebook Comments