Fyne gui api fahrenheit-convertor howto callback/event handler

I want to create a celcius-fahrenheit convertor using the gui toolkit fyne.
On enter of an entry i want to change the text of a label, ie the celcius converted to fahrenheit.
How do i do callbacks or handle enter events of the entry ?
More concrete an eventhandler on pressing enter of the entry widget.

Here is the code for a converter *3, one should use “bindings”

package main

import (
	"strconv"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/data/binding"
	"fyne.io/fyne/v2/widget"
)

func makeUI() fyne.CanvasObject {
	estring := ""
	myentrystring := binding.BindString(&estring)
	mylabelstring := binding.NewString()
	myentry := widget.NewEntryWithData(myentrystring)
	mylabel := widget.NewLabelWithData(mylabelstring)
	mybutton := widget.NewButton("Convert",
		func() {
			myinput, _ := strconv.Atoi(estring)
			myinput = myinput * 3
			myoutput := strconv.Itoa(myinput)
			mylabelstring.Set(myoutput)
		})
	return container.NewVBox(myentry, mybutton, mylabel)
}

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

	w.SetContent(makeUI())
	w.ShowAndRun()
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.