Golang-gui use and effect of third-party library andlabs/ui en

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.


GitHub has a lot of third-party GUI, this article takes Anblabs/ui library as an example, support cross-platform, also relatively easy to use, briefly introduce its usage and final display effect.



With the code, the copy code of the primer can be run directly, and some computers may need to download GCC:


package main

import (
    "github.com/andlabs/ui"
)

func main () {

    err: = ui.Main (func () {

        input: = ui.NewEntry ()
        input.SetText ("this is input element")
        input.LibuiControl ()
        spinbox: = ui.NewSpinbox (50, 150)
        spinbox.SetValue (55)
        slider: = ui.NewSlider (0, 100)
        slider.SetValue (10)
        processbar: = ui.NewProgressBar ()
        processbar.SetValue (50)
        combobox: = ui.NewCombobox ()
        combobox.Append ("select one")
        combobox.Append ("select two")
        combobox.Append ("select three")
        combobox.SetSelected (2)
        checkbox1: = ui.NewCheckbox ("GoLang")
        checkbox1.SetChecked (true)
        checkbox2: = ui.NewCheckbox ("C ++")
        checkbox3: = ui.NewCheckbox ("Python")
        checkbox4: = ui.NewCheckbox ("Other")
        checkbox_div: = ui.NewHorizontalBox ()
        checkbox_div.Append (checkbox1, true)
        checkbox_div.Append (checkbox2, true)
        checkbox_div.Append (checkbox3, true)
        checkbox_div.Append (checkbox4, true)
        radio: = ui.NewRadioButtons ()
        radio.Append ("GoLang")
        radio.Append ("C ++")
        radio.Append ("Python")
        radio.Append ("Other")
        checkbox_div.SetPadded (true)
        Separator: = ui.NewHorizontalSeparator ()
        Separator_label_l: = ui.NewLabel ("left")
        Separator_label_r: = ui.NewLabel ("right")
        Separator_div: = ui.NewHorizontalBox ()
        Separator_div.Append (Separator_label_l, true)
        Separator_div.Append (Separator, false)
        Separator_div.Append (Separator_label_r, true)
        Separator_div.SetPadded (true)
        datetimepicker: = ui.NewDateTimePicker ()

        // ----------------- Set a single child to a new group .------------

        container1: = ui.NewGroup ("input (input box)")
        container1.SetChild (input)
        container2: = ui.NewGroup ("spinbox (self-setting range box, the value can only be controlled by the arrow, and cannot be entered manually)")
        container2.SetChild (spinbox)
        container3: = ui.NewGroup ("slider (滑 片)")
        container3.SetChild (slider)
        container4: = ui.NewGroup ("processbar")
        container4.SetChild (processbar)
        container5: = ui.NewGroup ("checkbox"
        container5.SetChild (checkbox_div)
        container6: = ui.NewGroup ("radio (radio)")
        container6.SetChild (radio)
        container7: = ui.NewGroup ("combobox (drop-down box)")
        container7.SetChild (combobox)
        container8: = ui.NewGroup ("Separator")
        container8.SetChild (Separator_div)
        container9: = ui.NewGroup ("datetimepicker (time picker)")
        container9.SetChild (datetimepicker)

        // ------ Vertical containers ---------
        div: = ui.NewVerticalBox ()
        // ------ horizontally arranged containers
        boxs_1: = ui.NewHorizontalBox ()
        boxs_1.Append (container1, true)
        boxs_1.Append (container2, true)

        boxs_1.SetPadded (false)
        boxs_2: = ui.NewHorizontalBox ()
        boxs_2.Append (container3, true)
        boxs_2.Append (container4, true)

        boxs_3: = ui.NewHorizontalBox ()
        boxs_3.Append (container5, true)
        boxs_3.Append (container6, true)

        boxs_4: = ui.NewHorizontalBox ()
        boxs_4.Append (container7, true)
        boxs_4.Append (container8, true)

        div.Append (boxs_1, true)
        div.Append (boxs_2, true)
        div.Append (boxs_3, true)
        div.Append (boxs_4, true)
        div.Append (container9, true)
        div.SetPadded (false)
        window: = ui.NewWindow ("test111", 500, 500, true)

        window.SetChild (div)
        window.SetMargined (true)

        window.OnClosing (func (* ui.Window) bool {
            //ui.Quit ()
            return true
        })
        window.Show ()

    })
    if err! = nil {
        panic (err)
    }
} 





The final Test results show:










289 Reads
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.