Box

The box widget is a simple horizontal or vertical container that uses the box layout to lay out the child components. You can pass the objects to include in the widget.NewHBox() or widget.NewVBox()constructor functions.

It is also possible to add items to a box widget after it is created using Append() (to add after existing content) or Prepend() (to add before the content).

Example Code

            
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import (
	"fyne.io/fyne/app"
	"fyne.io/fyne/widget"
)

func main() {
	myApp := app.New()
	myWindow := myApp.NewWindow("Entry Widget")

	content := widget.NewVBox(widget.NewLabel("The top row of VBox"),
		widget.NewHBox(
			widget.NewLabel("Label 1"),
			widget.NewLabel("Label 2")))

	content.Append(widget.NewButton("Add more items", func() {
		content.Append(widget.NewLabel("Appended"))
	}))

	myWindow.SetContent(content)
	myWindow.ShowAndRun()
}