Search code examples
user-interfacegofyne

Append some text to a MultiLineEntry in fyne


I want to append some text to this MultiLineEntry as a button event. I know how to set a text but couldn't find any example for appending some text. Is there any other widget available for this purpose? This is my code so far:

package main

import (
    "fmt"
    "fyne.io/fyne/app"
    "fyne.io/fyne/container"
    "fyne.io/fyne/widget"
)

func main() {
    a := app.New()
    w := a.NewWindow("Hello")

    largeText := widget.NewMultiLineEntry()
    largeText.SetText("Lorem ipsum ...")
    largeText.SetPlaceHolder("Type here")

    form := &widget.Form{
        Items: []*widget.FormItem{
        },
        OnCancel: func() {
            fmt.Println("Cancelled")
        },
        OnSubmit: func() {
            fmt.Println("Form submitted")
            // EVENT TO APPEND TO MULTILINE
        },
    }

    w.SetContent(container.NewVBox(form,largeText))

    w.ShowAndRun()
}

Solution

  • You can first get then set:

        largeText := widget.NewMultiLineEntry()
        largeText.SetText("Lorem ipsum ...")
        originalText := largeText.Text
        fmt.Println(originalText)
        newText := originalText + "appending new text"
        largeText.SetText(newText)