Class 10 fyne GoLang GUI Canvas Rectangle
I this tutorial we are going to create a basic retangle in fyne & golang.
Here is the one line code to create a rectangle.
rect := canvas.NewRectangle(color.Black)
You can change color of rectangle
//fill color
rect.FillColor = color.NRGBA{R: 255, G: 255, B: 0, A: 255}
You can change stroke of rectangle
// Add Stroke
rect.StrokeColor = color.NRGBA{R: 255, G: 0, B: 0, A: 255}
You can change stroke width of rectangle
//Change stroke width rect.StrokeWidth = 5.0
package main
// importing fyne
import (
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
)
func main() {
// creating app
a := app.New()
// creating windows
w := a.NewWindow("Rectangle : Canvas")
rect := canvas.NewRectangle(color.Black)
//fill color
rect.FillColor = color.NRGBA{R: 255, G: 255, B: 0, A: 255}
rect.StrokeColor = color.NRGBA{R: 255, G: 0, B: 0, A: 255}
rect.StrokeWidth = 5.0
//setup content
w.SetContent(rect)
//resizing window
w.Resize(fyne.NewSize(400, 400))
w.ShowAndRun() // show and run app
}
[easy_media_download url=”http://blogvali.com/wp-content/uploads/fyne-golang-downloads/main10.go” text=”Download Code” color=”red_darker”]
Fyne GoLang GUI Course