Check Box – Fyne Golang GUI Tutorial 52

Check Box – Fyne Golang GUI Tutorial 52

<div>
<div>package main</div>
&nbsp;
<div>// import fyne</div>
<div>import (</div>
<div>    "image/color"</div>
&nbsp;
<div>    "fyne.io/fyne/v2"</div>
<div>    "fyne.io/fyne/v2/app"</div>
<div>    "fyne.io/fyne/v2/canvas"</div>
<div>    "fyne.io/fyne/v2/container"</div>
<div>    "fyne.io/fyne/v2/widget"</div>
<div>)</div>
&nbsp;
<div>func main() {</div>
<div>    // new app</div>
<div>    a := app.New()</div>
<div>    // new title and window</div>
<div>    w := a.NewWindow("check Box tutorial")</div>
<div>    // resize window</div>
<div>    w.Resize(fyne.NewSize(400, 400))</div>
<div>    // our first widget</div>
<div>    label := canvas.NewText("Your choice is ...", color.Black)</div>
<div>    // check box</div>
<div>    // first argument is name(string),</div>
<div>    // 2nd is function</div>
&nbsp;
<div>    chk_male := widget.NewCheck("male", func(b bool) {</div>
<div>        // change name of label</div>
<div>        if b == true {</div>
<div>            label.Text = "male"</div>
<div>            // refresh</div>
<div>            label.Refresh()</div>
<div>        } else {</div>
<div>            label.Text = "deseleted"</div>
<div>            // refresh</div>
<div>            label.Refresh()</div>
<div>        }</div>
<div>    })</div>
&nbsp;
<div>    // create new one for female</div>
<div>    chk_female := widget.NewCheck("female", func(b bool) {</div>
<div>        // change name of label</div>
<div>        if b == true {</div>
<div>            label.Text = "female"</div>
<div>            label.Hide()</div>
<div>            // refresh</div>
<div>            label.Refresh()</div>
<div>        } else {</div>
<div>            label.Text = "deseleted"</div>
<div>            label.Show()</div>
<div>            // refresh</div>
<div>            label.Refresh()</div>
<div>        }</div>
<div>    })</div>
&nbsp;
<div>    w.SetContent(</div>
<div>        // here we put all our widgets</div>
<div>        // we are done...</div>
<div>        // lets show content on screen</div>
<div>        container.NewVBox(</div>
<div>            label,</div>
<div>            chk_male,</div>
<div>            chk_female,</div>
<div>        ),</div>
<div>    )</div>
<div>    w.ShowAndRun()</div>
<div>}</div>
</div>

 

Download Code

Fyne Golang GUI Course

Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: