GUI programming with golang






I am using the andlabs/ui library for GUI with golang.  It's quite easy to setup on the mac and Linux. 





Video Guide





But was not that much straightforward to setup on windows.  It required the MinGW-w64 [ download from here ]. Make sure you are using the latest version of the MinGW-w64.  

Select the appropriate architecture during the installation.



Select architecture
Select architecture


After installation of the MinGW set to add the path to the bin folder of the MinGW in the PATH variable.



Set environment variableSet environment variable


Copy the code from the getting started to your favourite editor



package main
import (
"github.com/andlabs/ui"
)
func main() {
err := ui.Main(func() {
input := ui.NewEntry()
button := ui.NewButton("Click")
greeting := ui.NewLabel("")
box := ui.NewVerticalBox()
box.Append(ui.NewLabel("Label"), false)
box.Append(input, false)
box.Append(button, false)
box.Append(greeting, false)
window := ui.NewWindow("Use andlabs / Ui ", 200, 100, false)
window.SetMargined(true)
window.SetChild(box)
button.OnClicked(func(*ui.Button) {
greeting.SetText("Hello, " + input.Text() + "!")
})
window.OnClosing(func(*ui.Window) bool {
ui.Quit()
return true
})
window.Show()
})
if err != nil {
panic(err)
}
}



Run the go get command to pull the andlabs/ui package


CMD-PATH-TO-YOUR-PROJECT-ROOT-FOLDER > go get 



Comments

Popular Posts