Random Number Generator – Fyne GUI Golang tutorial 16

Random Number Generator – Fyne GUI Golang tutorial 16

 

In this Tutorial We are going to code a Random Number Generator.

It is a full fledge App.

You can create GUI and EXE format and distribute it anywhere.

[sourcecode language=”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 (
"fmt"
"image/color"
"math/rand"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)

func main() {
// creating new app
a := app.New()
// New window and title
w := a.NewWindow("Random Number Generator")
// Resize
w.Resize(fyne.NewSize(400, 400))
// Label
label1 := canvas.NewText("Rand Num Gen", color.Black)
label1.TextSize = 40
// Button
btn1 := widget.NewButton("Generate", func() {
// Ui is ready
// Now logic
rand1 := rand.Intn(1000)
label1.Text = fmt.Sprint(rand1) //conver int to string
label1.Refresh() // refresh and render UI
})
// Showing and setup content
w.SetContent(
// more than on widget so use container newVbox
container.NewVBox(
label1,
btn1,
),
)
//show and run
w.ShowAndRun()
}

 [/sourcecode] [easy_media_download url=”http://blogvali.com/wp-content/uploads/fyne-golang-downloads/main16.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: