Show and Hide widgets – Fyne Golang GUI Tutorial 53

Show and Hide widgets – Fyne Golang GUI Tutorial 53

 

 


package main
// import fyne
import (
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
func main() {
// New app
a := app.New()
// New title and window
w := a.NewWindow("Hide and show objects")
w.Resize(fyne.NewSize(400, 400))
// new rectangle
rect := canvas.NewRectangle(color.Black)
rect.Resize(fyne.NewSize(100, 100)) // 100x100 size
rect.Move(fyne.NewPos(50, 50)) // new position of rectangle
// check box to show and hide rectangle or any other object
// first argument is title of check box
// 2nd is function
chkbox := widget.NewCheck("hide", func(b bool) {
if b != true {
rect.Hide()
} else {
rect.Show() // show object/rectangle
}
})
// size of chkbox and position
chkbox.Move(fyne.NewPos(50, 200))
chkbox.Resize(fyne.NewSize(100, 50))
// setup content
w.SetContent(
// container without layout
container.NewWithoutLayout(
rect,
chkbox,
),
)
w.ShowAndRun()
}


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: