1

QR-Code Generator – Fyne Golang GUI Tutorial 64

QR-Code Generator – Fyne Golang GUI Tutorial 64

https://youtu.be/Gj8tQAWa3Y0

<div>
<div>package main</div>
<div>// import fyne</div>
<div>import (</div>
<div>    "fmt"</div>
<div>    "strconv"</div>
<div>    "fyne.io/fyne/v2"</div>
<div>    "fyne.io/fyne/v2/app"</div>
<div>    "fyne.io/fyne/v2/container"</div>
<div>    "fyne.io/fyne/v2/widget"</div>
<div>    "github.com/skip2/go-qrcode"</div>
<div>)</div>
<div>func main() {</div>
<div>    // new app</div>
<div>    a := app.New()</div>
<div>    // title &amp; window</div>
<div>    w := a.NewWindow("Qr code Generator")</div>
<div>    // resize</div>
<div>    w.Resize(fyne.NewSize(400, 400))</div>
<div>    // qrcode generator</div>
<div>    url := widget.NewEntry()</div>
<div>    url.SetPlaceHolder("Enter url ...")</div>
<div>    size := widget.NewEntry()</div>
<div>    size.SetPlaceHolder("Enter file size i.e 256 ...")</div>
<div>    size_1, _ := strconv.Atoi(size.Text)</div>
<div>    file_name := widget.NewEntry()</div>
<div>    file_name.SetPlaceHolder("Enter file name ...")</div>
<div>    btn := widget.NewButton("Create", func() {</div>
<div>        // we are going to use qrcode lib</div>
<div>        // go get -u github.com/skip2/go-qrcode/</div>
<div>        // install and use</div>
<div>        // file content</div>
<div>        // quality / resolution</div>
<div>        // size of image 256x256</div>
<div>        err1 := qrcode.WriteFile(</div>
<div>            url.Text,</div>
<div>            qrcode.Highest,</div>
<div>            size_1,</div>
<div>            fmt.Sprintf("%s.png", file_name.Text),</div>
<div>            // sprintf will add add suffix .png</div>
<div>        )</div>
<div>        if err1 != nil {</div>
<div>            fmt.Println(err1)</div>
<div>        }</div>
<div>    })</div>
<div>    w.SetContent(container.NewVBox(</div>
<div>        url,</div>
<div>        size,</div>
<div>        file_name,</div>
<div>        btn,</div>
<div>    ))</div>
<div>    w.ShowAndRun()</div>
<div>}</div>
</div>

 

Download Code

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 1 comments
anyone - 11 months ago

Hi thank for example.
A simple correction:

the line: ‘size_1, _ := strconv.Atoi(size.Text)’

must be placed inside callback function otherwise, you get an empty value from ‘size := widget.NewEntry()’

i.e:
size_1, _ := strconv.Atoi(size.Text)
err1 := qrcode.WriteFile(
url.Text,
qrcode.Highest,
size_1,
fmt.Sprintf(“%s.png”, file_name.Text),
// sprintf will add add suffix .png
)

Reply

Leave a Reply: