Code

Now that the library is installed, it's time to write some code. The following sample is andlabs UI equivalent of the hello world example we used in the Chapter 4, Walk - Building Graphical Windows Applications. Start by entering the following code into a new file, named hello.go:

package mainimport "github.com/andlabs/ui"func main() {        err := ui.Main(func() {                window := ui.NewWindow("Hello", 100, 50, false)                window.SetMargined(true)                window.OnClosing(func(*ui.Window) bool {                        ui.Quit()                        return true                })                button := ui.NewButton("Quit")                button.OnClicked(func(*ui.Button) {                        ui.Quit()                })                box := ui.NewVerticalBox()                box.Append(ui.NewLabel("Hello World!"), false)                box.Append(button, false)                window.SetChild(box)                window.Show()        })        if err != nil { panic(err) ...

Get Hands-On GUI Application Development in Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.