Associating RETURN key with a button in Fyne

1 week ago 11
ARTICLE AD BOX

I use widget.NewForm to create a login form with userid and password fields. It also has the default Cancel and Submit buttons. I have set the userid field to get default focus. I would like to be able to just hit the RETURN key to activate the Submit function but I can not find a way to do that.

This is made more complicated by the fact that there is no real Button available - the widget.Form hides that.

loginWindow := theApp.NewWindow("Login") idvalue := widget.NewEntry() pwvalue := widget.NewPasswordEntry() loginForm := widget.NewForm( widget.NewFormItem("Username", idvalue), widget.NewFormItem("Password", pwvalue)) loginForm.OnCancel = func() { loginWindow.Close() } loginForm.OnSubmit = func() { if !self.Login( idvalue.Text ) { ErrorPopup("Not a known user name") return } start() loginWindow.Close() } loginWindow.SetContent(loginForm) loginWindow.Canvas().Focus(idvalue)
Read Entire Article