安装依赖
go get github.com/lxn/walk
go get github.com/akavel/rsrc
rsrc
go-gui/gui.go
package main
import (
"strings"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
func main() {
var inTE, outTE *walk.TextEdit
MainWindow{
Title: "xiaochuan测试",
MinSize: Size{600, 400},
Layout: VBox{},
Children: []Widget{
HSplitter{
Children: []Widget{
TextEdit{AssignTo: &inTE, MaxLength: 10},
TextEdit{AssignTo: &outTE, ReadOnly: true},
},
},
PushButton{
Text: "SCREAM",
OnClicked: func() {
outTE.SetText(strings.ToUpper(inTE.Text()))
},
},
},
}.Run()
}
go mod init go-gui
manifestgo-gui/go-gui.exe.manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="SomeFunkyNameHere" type="win32"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True</dpiAware>
</windowsSettings>
</application>
</assembly>
rsrc -manifest go-gui.exe.manifest -o rsrc.syso
go build -ldflags="-H windowsgui"
go-gui.exe
go-gui.exemanifest
添加图标
rsrc -manifest go-gui.exe.manifest -ico favicon.ico -o rsrc.syso
go build -ldflags="-H windowsgui"
favicon.ico