Cross OS desktop GUI with GO and Fyne - Intro

May 5, 2019

What is Fyne?

Fyne is a UI toolkit designed to provide cross-platform graphics that appear identical on all supported platforms.

By default Fyne uses the gl golang bindings which means you need a working OpenGL configuration.

  • Debian/Ubuntu based systems may also need to install the libgl1-mesa-dev and xorg-dev packages.

  • Windows: various compiler packages are available Cygwin, MSYS2 and TDM-GCC should work. I use MSYS2 is the easiest to install - download the package and run it.

    • to compile Fyne applications you will need to use the MSYS2 command prompt

How to install Fyne’s core library

go get -u fyne.io/fyne

Hello Fyne’s World

package main
   
import (
  "fyne.io/fyne/app"
  "fyne.io/fyne/widget"
)
   
func main() {
   app := app.New()
   win := app.NewWindow("Hello World")
   win.SetContent(widget.NewVBox(
      widget.NewLabel("Hello World!"),
      widget.NewButton("Quit", func() {
         app.Quit()
      }),
   ))
   
   win.ShowAndRun()
}

Saving this file with the name hello.go and running it:

go run hello.go

we will see a simple app that on macOS will looks like this:

Hello Fyne

Fyne follows the Material Design guidelines.

  • you can build and specify your own theme or the other available light theme

To specify a different theme simply add the instruction:

app.Settings().SetTheme(theme.LightTheme()) 

Here the previous example with the light theme:

package main
   
import (
  "fyne.io/fyne/app"
  "fyne.io/fyne/widget"
  "fyne.io/fyne/theme"
)
   
func main() {
   app := app.New()
   app.Settings().SetTheme(theme.LightTheme())

   win := app.NewWindow("Hello World")
   win.SetContent(widget.NewVBox(
      widget.NewLabel("Hello World!"),
      widget.NewButton("Quit", func() {
         app.Quit()
      }),
   ))
   
   win.ShowAndRun()
}

Hello Fyne

For today that’s all. Thank you for your time!

Did you like the post? If so checkout the next post about fyne.layout.