Quantcast
Channel: 看得透又看得远者prevail. ppt.cc/flUmLx ppt.cc/fqtgqx ppt.cc/fZsXUx ppt.cc/fhWnZx ppt.cc/fnrkVx ppt.cc/f2CBVx
Viewing all articles
Browse latest Browse all 20515

go语言如何开发带UI的软件?

$
0
0

About Walk

Walk is a “Windows Application Library Kit” for the Go Programming Language.
Its primarily useful for Desktop GUI development, but there is some more stuff.

Setup

Make sure you have a working Go installation. See Getting Started
Note
Go 1.0.x doesn’t work with walk anymore, Make sure you use Go 1.1.x
To Install
Now run go get github.com/lxn/walk

Using Walk

The preferred way to create GUIs with Walk is to use its declarative sub package, as illustrated in this small example:
test.go
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()
}
Build app
In the directory containing test.go run
go build 
To get rid of the cmd window, instead run
go build -ldflags="-H windowsgui"
Create Manifest test.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>
</assembly>
Run app
test.exe 
Sample Output (Windows 7)

More Examples
There are some examples that should get you started.

Application Manifest Files

Walk requires Common Controls 6. This means that you must put an appropriate application manifest file either next to your executable or embedded as a resource.
You can copy one of the application manifest files that come with the examples.
IMPORTANT: Do not launch your executable before the manifest file is in place. If you do anyway, the program will not run properly. And worse, Windows will not recognize a manifest file, you later drop next to the executable. To fix this, rebuild your executable and only launch it with a manifest file in place。

from https://github.com/lxn/walk

Viewing all articles
Browse latest Browse all 20515

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>