Golang: GUI(lxn/walk)初用

1. 包

https://github.com/lxn/walk

2. 打开Goland直接撸代码

package main

import (
	"github.com/lxn/walk"
	. "github.com/lxn/walk/declarative"
	"strings"
)

func main() {
	var inTE, outTE *walk.TextEdit

	MainWindow{
		Title:   "SCREAMO",
		MinSize: Size{600, 400},
		Layout:  VBox{},
		Children: []Widget{
			HSplitter{
				Children: []Widget{
					TextEdit{AssignTo: &inTE},
					TextEdit{AssignTo: &outTE, ReadOnly: true},
				},
			},
			PushButton{
				Text: "SCREAM",
				OnClicked: func() {
					outTE.SetText(strings.ToUpper(inTE.Text()))
				},
			},
		},
	}.Run()
}

3. 创建 Module文件

     参考 - https://blog.csdn.net/halo_hsuh/article/details/106213176

go.mod (Note: 此信息也是相关包, 和版本)

module uiTester

go 1.14

require (
	github.com/lxn/walk v0.0.0-20191128110447-55ccb3a9f5c1
	github.com/lxn/win v0.0.0-20191128105842-2da648fda5b4 // indirect
	golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect
	gopkg.in/Knetic/govaluate.v3 v3.0.0 // indirect
)

4. 创建了模块 和 启用模块之后(Note: 设置国内代理等), 缺失时goland提示同步依赖, 既可以点击同步依赖, 等待下载完成

5. 下载完成之后在上面源码之前添上一句

//go:generate D:\ProgramPath\GoPath\bin\rsrc.exe -manifest test.manifest -o rsrc.syso

Note: 相关工具 (下面的指令执行完会在gopath/bin路径下出现rsrc可执行文件, 笔者为此路径D:\ProgramPath\GoPath\bin\rsrc.exe): 

go get github.com/akavel/rsrc

6. 创建文件test.mainfest, 内容

<?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>

7.  即可编译了, 

go语言gui初拥

参考:

https://www.jianshu.com/p/28f371a378f0

https://blog.csdn.net/halo_hsuh/article/details/106654340

https://blog.csdn.net/halo_hsuh/article/details/106213176

猜你喜欢

转载自blog.csdn.net/halo_hsuh/article/details/106714135