Skip to content
andlabs edited this page Sep 22, 2014 · 15 revisions

In this example we will make a program that asks the user to enter their name, then prints it.

example screenshot

The complete code for this program is as follows. I will discuss each part of the code below.

package main

import (
	"github.com/andlabs/ui"
)

var window ui.Window

func main() {
	go ui.Do(func() {
		name := ui.NewTextField()
		button := ui.NewButton("Greet")
		greeting := ui.NewStandaloneLabel("")
		stack := ui.NewVerticalStack(
			ui.NewStandaloneLabel("Enter your name:"),
			name,
			button,
			greeting)
		button.OnClicked(func() {
			greeting.SetText("Hello, " + name.Text() + "!")
		})
		window = ui.NewWindow("Hello", 200, 100, stack)
		window.OnClosing(func() bool {
			ui.Stop()
			return true
		})
		window.Show()
	})
	err := ui.Go()
	if err != nil {
		panic(err)
	}
}
Clone this wiki locally