Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default theme from code using the fyne GUI framework?

Tags:

go

themes

fyne

I can run my Fyne application with FYNE_THEME=light to make it use a light background and running without this var it will default to dark. Is there a way to reverse this behaviour? Having the application start with the light theme by default?

like image 719
Andreas Gohr Avatar asked Jul 10 '26 16:07

Andreas Gohr


2 Answers

add

os.Setenv("FYNE_THEME", "light")

in func main() before you show and run the window.

App would start with light theme by default.

like image 114
yebowhatsay Avatar answered Jul 12 '26 06:07

yebowhatsay


You set the theme globally by running fyne_settings to change user theme.

go get fyne.io/fyne/cmd/fyne_settings

All fyne apps will respect the configuration set in that app.

If your intent is to override the user theme (be careful about doing this as their settings will be ignored) you can configure the app settings in code:

myApp.Settings().SetTheme(theme.LightTheme())
like image 34
andy.xyz Avatar answered Jul 12 '26 05:07

andy.xyz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!