Select Page

In this tutorial I cover the best GUI framework for Go. This is learn Go In one hour by writing a GUI app. Golang does not have a built in GUI library. Python has libraries such as PyQt. There are so many tutorials online to claim to demonstrate the most straightforward methods for Go GUIs, but they are mostly not. The answer is bindings to a C++ library named Qt.

Prerequisites

  1. Ubuntu 18.04

Step 1 – Install Golang

~/Downloads$ sudo tar -C /usr/local -xzf go1.11.2.linux-amd64.tar.gz

sudo nano /etc/profile

export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$(go env GOPATH)/bin
export GOPATH=$(go env GOPATH)

Run this command to be sure

/* If this result is blank you are missing the right lines in /etc/profile */
echo $GOPATH

Set your Go workspace now. Basically it should be in your user’s  directory. For example choose ehg/home/go with go being a new directory containing your new workspace. Inside go the structure should look like this below.

-go

–bin

–src

—myApp

—-main.go

–pkg

Step 2 – Install Docker

You will most likely run into a permission issue right away with Docker. 

My user {ehg} does not have the permissions to run Docker. Let’s change that. Now I can run the Docker service without using “sudo” every time.

# add $USER to docker group
sudo usermod -a -G docker $USER

Now if you are using VirtualBox like I am then a reboot is required for this change to take effect.

docker pull therecipe/qt:linux

docker pull therecipe/qt:windows_64_static

Step 3 – Compile and run 

Pull down the packages we need. 

go get -v github.com/therecipe/qt/cmd/…

Run the setup. This is optional but will show you a preview of all the native widget examples as it runs setup.

qtsetup -docker
# run which qtsetup if you can't find it
which qtsetup
# for me it's /usr/local/bin/qtdeploy

Run this command in the directory that contains main.go for your package level code. For example go > src > myApp > main.go

qtdeploy -docker build linux
# once that runs you'll want to run this
cd deploy/linux
# run the bash script to run the app
./myApp.sh

# same thing for Windows target only with an exe

qtdeploy -docker build windows_64_static

cd deploy/windows

./myApp.exe

Compile and run the example code for a basic app.

error: