Blink a button when pressed #5836
-
|
A few months ago I wrote a simple function to blink buttons when pressed. As of fyne 2.6.1 it stopped working. The simplest code I can think of is: package main import ( func Blink(b widget.Button) { func main() { var Btn *widget.Button win.SetContent(container.New(layout.NewCenterLayout(),Btn)) Running 'go mod init' then 'go mod tidy' with 2.6.1 does not blink the button when pressed. With 2.6.1, if I change the sleep time to say two seconds and comment out b.Enable() the button does get disabled but only after the timeout. This suggests to me that the new threading executes code in a different order to that specified. Adding Refresh() after the enable/disable lines does not help. I'm not especially concerned with this, it was only gloss after all but can anybody think of a work round that will work with 2.6.1? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
This is due to the change in thread handling when you upgrade to v2.6.0 (or beyond): https://docs.fyne.io/api/v2.6/upgrading.html Your button was previously running in a goroutine but is now running on the event thread. So blocking it with func Blink(b *widget.Button) {
b.Disable()
go func() {
time.Sleep(150 * time.Millisecond)
fyne.Do(b.Enable)
}()
} |
Beta Was this translation helpful? Give feedback.
This is due to the change in thread handling when you upgrade to v2.6.0 (or beyond): https://docs.fyne.io/api/v2.6/upgrading.html
Your button was previously running in a goroutine but is now running on the event thread. So blocking it with
time.Sleepis blocking updates. Do this instead: