Go实战--使用golang开发Windows Gui桌面程序(lxn/walk)

生命不止,继续 go go go!!!

golang官方并没有提供Windows gui库,但是今天还是要跟大家分享一下使用golang开发Windows桌面程序,当然又是面向github编程了。

知乎上有一个问答:
golang为什么没有官方的gui包?

这里,主要使用第三方库lxn/walk,进行Windows GUI编程。

lxn/walk

github地址:
https://github.com/lxn/walk

star:
2018

描述:
A Windows GUI toolkit for the Go Programming Language

获取:

go get github.com/lxn/walk

例子:

main.go

package main

import (
    "
已标记关键词 清除标记
![图片说明](https://img-ask.csdn.net/upload/201912/17/1576568318_853567.png) **我的需求是点击生成二维码 在下面展示二维码。 **部分代码如下,初学golang 请教各位大佬** ``` type MyMainWindow struct { *walk.MainWindow hcName *walk.Label userIdName *walk.Label startTime *walk.DateEdit endTime *walk.DateEdit hc, userId *walk.LineEdit imageView *walk.ImageView imageComposite *walk.Composite qrCount int } func (mw *MyMainWindow) ShowQRcode() { if mw.imageComposite != nil { mw.imageComposite.Dispose() } mw.getQRcode() widgets := []Widget{} for i:=1;i<=mw.qrCount;i++ { bitmap, err := walk.NewBitmapFromFile("qrcode/qr_"+strconv.Itoa(i)+".jpg") log.Println("qrcode/qr_"+strconv.Itoa(i)+".jpg") if err != nil { walk.MsgBox(mw, mw.Title(), err.Error(), walk.MsgBoxIconError) break } widget := ImageView{ Image: bitmap, Mode: ImageViewModeZoom, } widgets = append(widgets, widget) } imageComposite := Composite{ AssignTo: &mw.imageComposite, Layout: HBox{}, Children: widgets, } if err := imageComposite.Create(NewBuilder(mw)); err != nil { log.Println(err) } } func openWindow(){ mw := &MyMainWindow{} _, _ = MainWindow{ Title: "梅清打印量上报", MinSize: Size{600, 400}, Size:Size{1200,800}, Layout: VBox{MarginsZero: true}, Children: []Widget{ Composite{ Layout:HBox{}, Children: []Widget{ Label{AssignTo: &mw.hcName,Text: "医院编号"}, LineEdit{AssignTo: &mw.hc,}, Label{AssignTo: &mw.userIdName,Text: "工程师编号"}, LineEdit{AssignTo: &mw.userId,}, DateEdit{AssignTo:&mw.startTime, Format:"yyyy-MM-dd",}, DateEdit{AssignTo:&mw.endTime, Format:"yyyy-MM-dd",}, PushButton{ Text: "生成二维码", OnClicked: func(){ if len(mw.hc.Text()) == 0 { walk.MsgBox(mw, mw.Title(), "请输入医院编号", walk.MsgBoxIconError) log.Println("请输入医院编号") return } if len(mw.userId.Text()) == 0 { walk.MsgBox(mw, mw.Title(), "请输入工程师编号", walk.MsgBoxIconError) log.Println("请输入工程师编号") return } mw.ShowQRcode() }, }, }, }, Composite{ AssignTo:&mw.imageComposite, Layout:HBox{}, }, }, }.Run() } ``` 这是报错信息 ![图片说明](https://img-ask.csdn.net/upload/201912/24/1577177949_302636.png)
<div class="post-text" itemprop="text"> <p>i have downloaded a project from github for some testing. the code is in go language. when i edited the code and run , many errors occoured. I have tried to run project using D:\go>go run demo command. how should i run the project? </p> <p>here are the errors: </p> <pre><code>D:\go>go run hardentools-master bin\src\hardentools-master\powershell.go:20:2: cannot find package "errors" in any of: D:\go\bin\src\errors (from $GOROOT) C:\Users\admin\go\src\errors (from $GOPATH) bin\src\hardentools-master\gui.go:20:2: cannot find package "flag" in any of: D:\go\bin\src\flag (from $GOROOT) C:\Users\admin\go\src\flag (from $GOPATH) bin\src\hardentools-master\adobe.go:20:2: cannot find package "fmt" in any of: D:\go\bin\src\fmt (from $GOROOT) C:\Users\admin\go\src\fmt (from $GOPATH) bin\src\hardentools-master\gui.go:26:2: cannot find package "github.com/lxn/walk" in any of: D:\go\bin\src\github.com\lxn\walk (from $GOROOT) C:\Users\admin\go\src\github.com\lxn\walk (from $GOPATH) bin\src\hardentools-master\gui.go:27:2: cannot find package "github.com/lxn/walk/declarative" in any of: D:\go\bin\src\github.com\lxn\walk\declarative (from $GOROOT) C:\Users\admin\go\src\github.com\lxn\walk\declarative (from $GOPATH) bin\src\hardentools-master\adobe.go:22:2: cannot find package "golang.org/x/sys/windows/registry" in any of: D:\go\bin\src\golang.org\x\sys\windows egistry (from $GOROOT) C:\Users\admin\go\src\golang.org\x\sys\windows egistry (from $GOPATH) bin\src\hardentools-master\main.go:73:2: cannot find package "io" in any of: D:\go\bin\src\io (from $GOROOT) C:\Users\admin\go\src\io (from $GOPATH) bin\src\hardentools-master\gui.go:22:2: cannot find package "io/ioutil" in any of: D:\go\bin\src\io\ioutil (from $GOROOT) C:\Users\admin\go\src\io\ioutil (from $GOPATH) bin\src\hardentools-master\main.go:74:2: cannot find package "log" in any of: D:\go\bin\src\log (from $GOROOT) C:\Users\admin\go\src\log (from $GOPATH) bin\src\hardentools-master\gui.go:23:2: cannot find package "os" in any of: D:\go\bin\src\os (from $GOROOT) C:\Users\admin\go\src\os (from $GOPATH) </code></pre> </div>
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页
实付 29.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值