1

QR-Code Generator – Fyne Golang GUI Tutorial 64

QR-Code Generator – Fyne Golang GUI Tutorial 64


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

 

[easy_media_download url=”http://blogvali.com/wp-content/uploads/fyne-golang-downloads/main56.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 1 comments
anyone - a couple of years 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: