分享
Golang GUI基础1 -- JSON格式化小工具
90design · · 1746 次点击 · · 开始浏览这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。
What you are wasting today is tomorrow for those who died yesterday; what you hate now is the future you can not go back.
你所浪费的今天是昨天死去的人奢望的明天; 你所厌恶的现在是未来的你回不去的曾经。
本人入门Golang的gui, 只是想做一些小的工具日常工作使用, 因为对Golang的热爱已经到了如痴如醉的地步。
开始今天的lxn/walk练习:
package main
import (
"encoding/json"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
func main() {
var inTE, outTE *walk.TextEdit
MainWindow{
Title: "格式化工具",
MinSize: Size{600, 400},
Layout: VBox{},
Children: []Widget{
HSplitter{
Children: []Widget{
TextEdit{AssignTo: &inTE},
TextEdit{AssignTo: &outTE, ReadOnly: true},
},
},
PushButton{
Text: "格式化",
MinSize:Size{150, 36},
OnClicked: func() {
var jsonStr interface{}
err := json.Unmarshal([]byte(inTE.Text()), &jsonStr)
jsonStr, _ = json.MarshalIndent(jsonStr, "\r\n", "\t")
if err != nil {
// 暂时未找到设置颜色值
//outTE.SetTextColor(walk.Color(32))
outTE.SetText("数据格式不正确")
} else {
outTE.SetText(string(jsonStr.([]uint8)))
}
},
},
},
}.Run()
}
本案例尽在Windows 10 上测试。
运行首先使用rsrc工具编译加载manifest文件,然后build生成可执行文件
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信1746 次点击
添加一条新回复
(您需要 后才能回复 没有账号 ?)
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
What you are wasting today is tomorrow for those who died yesterday; what you hate now is the future you can not go back.
你所浪费的今天是昨天死去的人奢望的明天; 你所厌恶的现在是未来的你回不去的曾经。
本人入门Golang的gui, 只是想做一些小的工具日常工作使用, 因为对Golang的热爱已经到了如痴如醉的地步。
开始今天的lxn/walk练习:
package main
import (
"encoding/json"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
func main() {
var inTE, outTE *walk.TextEdit
MainWindow{
Title: "格式化工具",
MinSize: Size{600, 400},
Layout: VBox{},
Children: []Widget{
HSplitter{
Children: []Widget{
TextEdit{AssignTo: &inTE},
TextEdit{AssignTo: &outTE, ReadOnly: true},
},
},
PushButton{
Text: "格式化",
MinSize:Size{150, 36},
OnClicked: func() {
var jsonStr interface{}
err := json.Unmarshal([]byte(inTE.Text()), &jsonStr)
jsonStr, _ = json.MarshalIndent(jsonStr, "\r\n", "\t")
if err != nil {
// 暂时未找到设置颜色值
//outTE.SetTextColor(walk.Color(32))
outTE.SetText("数据格式不正确")
} else {
outTE.SetText(string(jsonStr.([]uint8)))
}
},
},
},
}.Run()
}
本案例尽在Windows 10 上测试。
运行首先使用rsrc工具编译加载manifest文件,然后build生成可执行文件