在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庫,還有其他更多的庫可供選擇。你可以根據自己的需求和偏好選擇合適的庫來編寫界面程序。