Themes Dark Light – Fyne GUI Golang tutorial 22

Themes Dark Light – Fyne GUI Golang tutorial 22

Fyne theme has 2 default themes? Dark & Light but you can customize to create your own.

Want to change Theme of your Fyne GUI app ?

This is very easy in Fyne.

You can easily create custom themes in Fyne.

But No need if there is already available.

 

How to change to dark theme in fyne ?

You can use  a.Settings().SetTheme(theme.DarkTheme()) to change to dark theme.

 

How to use light theme in fyne ?

You can use a.Settings().SetTheme(theme.LightTheme()) to change to Light theme.

 

package main
// importing fyne
import (
    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/container"
    "fyne.io/fyne/v2/theme"
    "fyne.io/fyne/v2/widget"
)
func main() {
    // New app
    a := app.New()
    // Theme change
    // a.Settings().SetTheme(theme.LightTheme())
    // Dark Theme
    a.Settings().SetTheme(theme.DarkTheme())
    // New Window
    w := a.NewWindow("Fyne Themes# Dark & Light")
    w.Resize(fyne.NewSize(400, 400))
    // New Widget
    label := widget.NewLabel("Fyne Themese")
    btn1 := widget.NewButton("light", func() {
        // light theme
        a.Settings().SetTheme(theme.LightTheme())
    })
    btn2 := widget.NewButton("dark", func() {
        // Dark theme
        a.Settings().SetTheme(theme.DarkTheme())
    })
    btn3 := widget.NewButton("Exit", func() {
        // Exit
        a.Quit()
    })
    w.SetContent(
        container.NewVBox(
            label,
            btn1,
            btn2,
            btn3,
        ),
    )
    // Show and run
    w.ShowAndRun()
}

Download Code

Fyne Golang GUI Course

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: