Skip to content

Custom Dialog

Display custom dialogs in Fyne using widget and container combinations for flexible UI interactions.

Show Code
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
func main() {
a := app.New()
w := a.NewWindow("Custom Info Dialog")
btn := widget.NewButton("Show Custom Info", func() {
// Icon
icon := widget.NewIcon(theme.InfoIcon())
// Styled text
text := canvas.NewText("This is a custom information dialog!", theme.Color(theme.ColorNameForeground))
text.TextSize = 16
// Put icon + text in horizontal layout
content := container.NewHBox(icon, text)
// Show custom dialog
dialog.ShowCustom("Custom Info", "OK", content, w)
})
w.SetContent(container.NewCenter(btn))
w.Resize(fyne.NewSize(400, 200))
w.ShowAndRun()
}
Show Code
package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
func showCustomConfirm(win fyne.Window, title, message string, onConfirm func()) {
// Icon
icon := widget.NewIcon(theme.QuestionIcon())
// Message
text := canvas.NewText(message, theme.Color(theme.ColorNameForeground))
text.TextSize = 14
content := container.NewHBox(icon, text)
// Custom dialog with "Confirm" and "Cancel"
d := dialog.NewCustomConfirm(
title,
"Confirm",
"Cancel",
content,
func(confirmed bool) {
if confirmed {
onConfirm()
} else {
fmt.Println("User canceled")
}
},
win,
)
d.Show()
}
func main() {
a := app.New()
w := a.NewWindow("Custom Confirm")
btn := widget.NewButton("Delete File", func() {
showCustomConfirm(w, "Confirm Deletion",
"Are you sure you want to delete this file?.",
func() {
fmt.Println("File deleted!")
})
})
w.SetContent(container.NewCenter(btn))
w.Resize(fyne.NewSize(450, 250))
w.ShowAndRun()
}