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

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