安装库:

go get github.com/lxn/walk

代码:

package mainimport ("strings""github.com/lxn/walk". "github.com/lxn/walk/declarative"
)func main() {var le *walk.LineEditvar wv *walk.WebViewvar mw *walk.MainWindowMainWindow{AssignTo: &mw,Icon:     Bind("a.ico"),Title:    "Big Screen",MinSize:  Size{800, 600},Layout:   VBox{MarginsZero: true},Children: []Widget{LineEdit{AssignTo: &le,Text:     Bind("wv.URL"),OnKeyDown: func(key walk.Key) {if key == walk.KeyReturn {wv.SetURL(le.Text())}},},WebView{AssignTo: &wv,Name:     "wv",URL:      "https://www.baidu.com",},},Functions: map[string]func(args ...interface{}) (interface{}, error){"icon": func(args ...interface{}) (interface{}, error) {if strings.HasPrefix(args[0].(string), "https") {return "check", nil}return "stop", nil},},}.Run()}

直接编译运行是不行的,windows里还需要一个manifest文件。

下载工具:

go get github.com/akavel/rsrc

 进入github.com/akavel/rsrc文件夹:执行go build,再把生成的rsrc.exe拷贝到GOROOT目录。

创建一个test.manifest文件,复制代码:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"><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><asmv3:application><asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings"><dpiAware>true</dpiAware></asmv3:windowsSettings></asmv3:application>
</assembly>

执行命令生成rsrc.syso文件:

rsrc -manifest test.manifest -o rsrc.syso

 然后编译程序:

go build

此时生成的文件会带个dos框,换个命令编译:

go build -ldflags="-H windowsgui" -o test.exe

完美