Create EXE file with custom icon in Fyne & golang GUI

Create EXE file with custom icon in Fyne & golang GUI

Do you want to create .exe file with custom icon in Fyne & Golang. Here is the tutorial plus video.

How to install fyne

go get -u fyne.io/fyne/cmd/fyne

Here is the go path

$GOPATH/bin

Android command
fyne package -os android -appID my.domain.appname

Windows command
fyne package -os windows -icon bmi.jpg

 

Source code of project I used


package main
import (
    "fmt"
    "image/color"
    "math"
    "strconv"
    "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() {
    // Convert logic to Beautiful UI
    // New app
    a := app.New()
    //New title
    w := a.NewWindow("BMI Calc")
    // resize
    w.Resize(fyne.NewSize(400, 400))
    // label
    label := canvas.NewText("BMI Calc", color.Black)
    label.Alignment = fyne.TextAlignCenter
    label.TextSize = 20
    //logo
    logo1 := canvas.NewImageFromFile("bmi.jpg")
    logo1.FillMode = canvas.ImageFillOriginal
    // for resutl
    result := canvas.NewText("", color.Black)
    result.Alignment = fyne.TextAlignCenter
    result.TextSize = 20
    // input height
    inputH := widget.NewEntry()
    inputH.SetPlaceHolder("Enter height in cm..")
    inputW := widget.NewEntry()
    inputW.SetPlaceHolder("Enter Weight in KG..")
    btn1 := widget.NewButton("Calc BMI", func() {
        h, _ := strconv.ParseFloat(inputH.Text, 64)
        w, _ := strconv.ParseFloat(inputW.Text, 64)
        result.Text = calculateBMI(h/100, w)
        result.Refresh()
    })
    // setup content
    w.SetContent(
        container.NewVBox(
            label,
            logo1,
            inputH,
            inputW,
            btn1,
            result,
        ))
    w.ShowAndRun()
}
// converting into function
func calculateBMI(height, weight float64) string {
    // copy the above code and paste here
    // BMI formula BMI = w/ h ^2
    var BMI float64 = weight / math.Pow(height, 2) // math.Pow(base,power)
    // conditions
    // BMI <= 18.4 "You are underweight.")
    if BMI <= 18.4 {
        fmt.Println("You are underweight.")
        return "You are underweight."
    } else if BMI <= 24.9 { // BMI <= 24.9  "You are healthy.")
        fmt.Println("You are healthy.")
        return "You are healthy."
    } else if BMI <= 29.9 { // BMI <= 29.9  "You are over weight.")
        fmt.Println("You are over weight.")
        return "You are over weight."
    } else if BMI <= 34.9 { // BMI <= 34.9  "You are severely over weight.")
        fmt.Println("You are severely over weight.")
        return "You are severely over weight."
    } else if BMI <= 39.9 { // BMI <= 39.9  "You are obese.")
        fmt.Println("You are obese.")
        return "You are obese."
    } else { // "You are severely obese.")
        fmt.Println("You are severely obese.")
        return "You are severely obese."
    }
}

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: