Golang GUI基礎1 -- JSON格式化小工具

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

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 mainimport ("encoding/json""github.com/lxn/walk". "github.com/lxn/walk/declarative")func main() {var inTE, outTE *walk.TextEditMainWindow{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產生可執行檔

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.