Using Golang to create a Windows GUI graphical interface-walk

Source: Internet
Author: User

Recently learning Golang, thinking about whether you can use Golang to develop a Windows GUI software, began to find information on the Internet, found that Golang has a walk library can implement this function, the following to recognize Golang walk.

About Walk Interface Library (official introduction):

Walk is a Windows Application Library suite for Golang, which is used primarily for desktop GUI development, but there are more things.

before we begin, we should note that Walk official statement, limited to support only Golang 1.8.x above, 1.7.x below is not supported .

1. We need to install the Walk library first, run the following command

  

Go get Github.com/lxn/walk

The installation time may take dozens of seconds due to the reason of GitHub's foreign server, and wait patiently

When the 2.walk library is installed, we create a test.go file under the project and fill in the code:

Package Mainimport ("Github.com/lxn/walk". "Github.com/lxn/walk/declarative" "strings") func main () {var inTE, Outte *walk. Texteditmainwindow{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 ()}

After the code is written, we can not directly go to build package, Golang graphics EXE needs to rely on manifest to run properly. But go does not provide all the functions of resource packaging, so to embed manifest EXE file, also need a tool: rsrc.

3. We install a tool rsrc

Go get github.com/akavel/rsrc

When the 4.RSRC tool is installed, we also need to build amanifest文件 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>

5. Buildrsrc.syso

Rsrc-manifest Test.manifest-o Rsrc.syso

6. Then package as EXE file

Go Build

When the EXE is opened, it takes the cmd command window, and we then remove the command window

Go build-ldflags= "-H Windowsgui"

And then open the EXE to do it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.