The first curious topic when learning a new programming language, frameworks and what can be done about this technology.
Go programming language didn’t publish a desktop application framework as official. Because it is not its goal… The goal of Go is to develop system and Web server-focused infrastructure applications.
How is it?
I’ve seen many different ways to do desktop programming with Go. We can build desktop application using Electron.js, HTML-JS etc… But we want to use native solutions. That’s why, we’ll focus on the native Go frameworks.
What can we use?
- http://libs.club/golang/media/gui (More than one)
- https://github.com/andlabs/ui
- https://github.com/alexflint/gallium
- https://github.com/lxn/walk
- -> https://github.com/lxn/walk/tree/master/examples
- https://github.com/google/gxui
- https://github.com/mattn/go-gtk
- https://github.com/peterhoward42/godesktopgui
My suggestion would be to use the Go framework created to work with Qt/QML. Qt is a very advanced and widely used framework. I’ll use the ‘ andlabs/ui ‘ framework as an example of this article. Actually, I’ll just do copy/paste from GitHub
Let’s start with example:
First, download the library ‘ andlabs/ui ‘:
go get github.com/andlabs/ui
Source code of the application:
package main
import (
"github.com/andlabs/ui"
)
func main() {
err := ui.Main(func() {
name := ui.NewEntry()
button := ui.NewButton("Selamla")
greeting := ui.NewLabel("")
box := ui.NewVerticalBox()
box.Append(ui.NewLabel("Ad:"), false)
box.Append(name, false)
box.Append(button, false)
box.Append(greeting, false)
window := ui.NewWindow("Merhaba", 250, 100, false)
window.SetChild(box)
button.OnClicked(func(*ui.Button) {
greeting.SetText("Merhaba, " + name.Text() + "!")
})
window.OnClosing(func(*ui.Window) bool {
ui.Quit()
return true
})
window.Show()
})
if err != nil {
panic(err)
}
}
When we run the project we’ll see the UI of the application. In the same way, we can work with ‘ go build ‘ simply by compiling the project We’ll be producing and .exe in this way. But it is not enough! Because this project will work with a console application in the background.
Therefore, we need to compile this application in the following way.
go build -ldflags -H=windowsgui main.go
Screenshots of the application
The source code of the above application you can access from the following link:
Original : http://www.cihanozhan.com/desktop-application-development-with-go/