File Handling Write Files – Fyne GUI Golang tutorial 46

File Handling Write Files – Fyne GUI Golang tutorial 46


Source Code #

<div>package main</div>
<div>// import fyne</div>
<div>import (</div>
<div>    ""</div>
<div>    ""</div>
<div>    ""</div>
<div>    ""</div>
<div>    ""</div>
<div>func main() {</div>
<div>    // New app</div>
<div>    a := app.New()</div>
<div>    w := a.NewWindow("Save files...")</div>
<div>    // file handling tutorial</div>
<div>    // Resize</div>
<div>    w.Resize(fyne.NewSize(400, 400))</div>
<div>    // Entry to enter text</div>
<div>    entry := widget.NewMultiLineEntry()</div>
<div>    // btn to save text</div>
<div>    btn := widget.NewButton("Save .txt file", func() {</div>
<div>        // dialog</div>
<div>        // 2 arguments</div>
<div>        // one function</div>
<div>        // 2nd parent window</div>
<div>        fileDialog := dialog.NewFileSave(</div>
<div>            // data of entry</div>
<div>            // []byte() function is used to convert</div>
<div>            // string to bytes slice</div>
<div>            func(uc fyne.URIWriteCloser, _ error) {</div>
<div>                data := []byte(entry.Text)</div>
<div>                //_ to ignore error</div>
<div>                // Lets write data</div>
<div>                uc.Write(data)</div>
<div>            }, w) // w is parent window</div>
<div>        // File name(temporary)</div>
<div>        fileDialog.SetFileName("anyFileName.txt")</div>
<div>        // Show and setup</div>
<div>        fileDialog.Show()</div>
<div>    })</div>
<div>    // show our two widgets on screen</div>
<div>    w.SetContent(</div>
<div>        container.NewVBox(</div>
<div>            entry,</div>
<div>            btn,</div>
<div>        ),</div>
<div>    )</div>
<div>    w.ShowAndRun()</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 0 comments

Leave a Reply: