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.
[sourcecode lang=”go”] rect := canvas.NewRectangle(color.Black)
[/sourcecode] You can change color of rectangle

[sourcecode lang=”go”] //fill color
rect.FillColor = color.NRGBA{R: 255, G: 255, B: 0, A: 255}

[/sourcecode] You can change stroke of rectangle

[sourcecode lang=”go”] // Add Stroke
rect.StrokeColor = color.NRGBA{R: 255, G: 0, B: 0, A: 255}

[/sourcecode]

You can change stroke width of rectangle

[sourcecode lang=”go”] //Change stroke width
rect.StrokeWidth = 5.0
[/sourcecode] [sourcecode lang=”go” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”1-3,6,9″ htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false” title=”Source Code main.go”]

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
}

[/sourcecode] [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

 

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: