Layout NewVBox NewHBox – Fyne GUI Golang tutorial 15

Layout NewVBox NewHBox – Fyne GUI Golang tutorial 15

If you want to use and display more than one widges in GUI App. You need to use layout.

Though we have tons of choices. But we are going to use to simple layout for horizontal and vertical.

For Horizontal layout we will use NewHBox layout.

NewHBox , Horizontal Layout

 

And for Vertical we are going to use NewVBox layout.

NewVBox , Vertical Layout

 

 

package main
// importing fyne
import (
    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/container"
    "fyne.io/fyne/v2/widget"
)
func main() {
    // creating new app
    a := app.New()
    // creating new window and title
    w := a.NewWindow("Layout NewVBox and NewHbox")
    w.Resize(fyne.NewSize(400, 400))
    // New button
    btn1 := widget.NewButton("click me", func() {
    })
    label1 := widget.NewLabel("here is my text")
    // NewHBox
    box1 := container.NewHBox( // Horizontal
        btn1,
        label1,
    )
    // NewVBox
    // box1 := container.NewVBox( // Vertical
    //  btn1,
    //  label1,
    // )
    // setup content
    w.SetContent(
        box1,
    )
    // show and run
    w.ShowAndRun()
}

Download Code

 

 

 

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: