Label
Alabel is used to display texts in a Fyne application, including static text and dynamically updated content.
Basic Label
Section titled “Basic Label”Show Code
package main
import ( "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/widget")
func main() { myApp := app.New() myWindow := myApp.NewWindow("Label Widget")
content := widget.NewLabel("Simple Label")
myWindow.SetContent(content) myWindow.ShowAndRun()}Label With Style
Section titled “Label With Style”Show Code
package main
import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/widget")
func main() { myApp := app.New() myWindow := myApp.NewWindow("Label Widget")
content := widget.NewLabelWithStyle("Text", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
myWindow.SetContent(content) myWindow.ShowAndRun()}Label With Data
Section titled “Label With Data”Show Code
package main
import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/data/binding" "fyne.io/fyne/v2/widget")
func main() { myApp := app.New() myWindow := myApp.NewWindow("Label with Data Binding")
// Create a bound string data := binding.NewString() data.Set("Name: John Doe\nAge: 28")
// Create a label bound to the data label := widget.NewLabelWithData(data)
// Button to update the data updateButton := widget.NewButton("Update Data", func() { data.Set("Name: Jane Smith\nAge: 32") })
// Arrange vertically content := container.NewVBox( label, updateButton, )
myWindow.SetContent(content) myWindow.Resize(fyne.NewSize(300, 150)) myWindow.ShowAndRun()}