在Go语言中,可以使用第三方的GUI库来编写界面程序。以下是一些常用的GUI库:
package main
import (
"github.com/mattn/go-gtk/gtk"
)
func main() {
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("Hello, Go-GTK!")
window.Connect("destroy", func() {
gtk.MainQuit()
})
label := gtk.NewLabel("Hello, Go-GTK!")
window.Add(label)
window.ShowAll()
gtk.Main()
}
package main
import (
"github.com/zserge/lorca"
)
func main() {
ui, _ := lorca.New("", "", 480, 320)
defer ui.Close()
ui.Bind("sayHello", func() {
ui.Eval(`alert("Hello, Lorca!")`)
})
ui.Load("data:text/html," + url.PathEscape(`
<html>
<body>
<button onclick="sayHello()">Click me</button>
</body>
</html>
`))
<-ui.Done()
}
package main
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
func main() {
var mainWindow *walk.MainWindow
MainWindow{
Title: "Hello, Walk!",
MinSize: Size{Width: 300, Height: 200},
Layout: VBox{},
Children: []Widget{
Label{Text: "Hello, Walk!"},
PushButton{
Text: "Click me",
OnClicked: func() {
walk.MsgBox(mainWindow, "Hello", "Hello, Walk!", walk.MsgBoxIconInformation)
},
},
},
AssignTo: &mainWindow,
}.Run()
}
这些只是一小部分可用的GUI库,还有其他更多的库可供选择。你可以根据自己的需求和偏好选择合适的库来编写界面程序。