Open Text Files – Fyne GUI Golang tutorial 45

Open Text Files – Fyne GUI Golang tutorial 45

Want to read and write files in Fyne? Fortunately it is very easy.

This tutorial is about how to read a text file from your harddrive.


Open Text Files – Fyne GUI Golang tutorial 45

Source Code

package main
// import fyne
import (
func main() {
    // New app
    a := app.New()
    //New title and window
    w := a.NewWindow("Open file in FYNE")
    // resize window
    w.Resize(fyne.NewSize(400, 400))
    // New Buttton
    btn := widget.NewButton("Open .txt files", func() {
        // Using dialogs to open files
        // first argument func(fyne.URIReadCloser, error)
        // 2nd is parent window in our case "w"
        // r for reader
        // _ is ignore error
        file_Dialog := dialog.NewFileOpen(
            func(r fyne.URIReadCloser, _ error) {
                // read files
                data, _ := ioutil.ReadAll(r)
                // reader will read file and store data
                // now result
                result := fyne.NewStaticResource("name", data)
                // lets display our data in label or entry
                entry := widget.NewMultiLineEntry()
                // string() function convert byte to string
                // Lets show and setup content
                // tile of our new window
                w := fyne.CurrentApp().NewWindow(
                    string(result.StaticName)) // title/name
                w.Resize(fyne.NewSize(400, 400))
                // show/display content
                // we are almost done
            }, w)
        // fiter to open .txt files only
        // array/slice of strings/extensions
        // Show file selection dialog.
    // lets show button in parent window


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

Short and simple


Leave a Reply: