Fyne Gui Goroutine在几个滴答后停止了
我已经开始编写一个简单的GUI应用程序,该应用程序仅在左上角显示当前时间。我的问题是,在我的M1 Mac上2-3秒后,时钟刻度停止。有趣的是,当我在时间更新旁边添加一个打印语句时,它会完美运行。将其删除,然后在几个滴答后再次停止了goroutine。这是它的代码:
package main
import (
// "fmt"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
func updateTime(clock *widget.Label) {
formatted := time.Now().Format("15:04:05")
clock.SetText(formatted)
}
func main() {
a := app.New()
w := a.NewWindow("Clock")
w.Resize(fyne.NewSize(500, 400))
row := fyne.NewContainerWithLayout(
layout.NewVBoxLayout(),
)
clock := widget.NewLabel("Starting Clock")
row.Add(clock)
w.SetContent(row)
go func() {
for range time.Tick(time.Second) {
// fmt.Println("Hello")
updateTime(clock)
}
}()
w.ShowAndRun()
}
我在这里缺少一些东西,还是Fyne只是一个问题?
I have started to write a simple Go GUI application which - for now - only displays the current time at the top left corner. My issue is that the Goroutine which makes the clock tick stops after 2-3 seconds on my M1 Mac. The interesting thing is, that when I add a print statement next to my time update one, it runs flawlessly. Remove it, and the Goroutine just halts again after a couple of ticks. Here's the code for it:
package main
import (
// "fmt"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
func updateTime(clock *widget.Label) {
formatted := time.Now().Format("15:04:05")
clock.SetText(formatted)
}
func main() {
a := app.New()
w := a.NewWindow("Clock")
w.Resize(fyne.NewSize(500, 400))
row := fyne.NewContainerWithLayout(
layout.NewVBoxLayout(),
)
clock := widget.NewLabel("Starting Clock")
row.Add(clock)
w.SetContent(row)
go func() {
for range time.Tick(time.Second) {
// fmt.Println("Hello")
updateTime(clock)
}
}()
w.ShowAndRun()
}
Is there something I'm missing here, or could this just be an issue with Fyne?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论