Skip to content

Radio Button

A Radio Button in Fyne allows users to select exactly one option from a group. It’s useful when you want mutually exclusive choices.

Show Code
package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("Radio Group Example")
// Label to display selected option
label := widget.NewLabel("No option selected")
// Create a radio group
radio := widget.NewRadioGroup(
[]string{"Option A", "Option B", "Option C"},
func(selected string) {
if selected == "" {
label.SetText("No option selected")
} else {
label.SetText(fmt.Sprintf("Selected: %s", selected))
}
},
)
// Pre-select an option
radio.SetSelected("Option B")
// Layout
content := container.NewVBox(
label,
radio,
)
myWindow.SetContent(content)
myWindow.Resize(fyne.NewSize(300, 200))
myWindow.ShowAndRun()
}