How to change the background color in fyne golang GUI?

135 Views Asked by At

How to make a colored background in fyne? I can use a rectangle in container.NewMax, but I don't think that's the right approach. maybe there is some way to change the background of the container?

If I use the rectangle approach in container.NewMax , then I don't know how I should position the other elements so that my container.NewMax stays in the background and completely covers the window.

background := canvas.NewRectangle(color.RGBA{R: 205, G: 92, B: 92, A: 255})
container.NewMax(background)

btn := widget.NewButton("test", func() {})
2

There are 2 best solutions below

0
Christoph On

Using rect is correct, MaxLayout takes full space of parent. So you could use like container.NewMax(background, container.NewHBox(btn))

0
andy.xyz On

Alternatively you could set the background of your window with a custom theme https://docs.fyne.io/extend/custom-theme