fyne文本颜色应用
canvas.Text
用于 Fyne 中的文本渲染,通过指定文本和文本颜色创建。
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"image/color"
"time"
)
const ApplicationTitle string = "ASM to HEX Converter"
const ApplicationTitleToggle string = "HEX to ASM Converter"
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("VPN")
userLable := widget.NewLabel("USERNAME")
userEntry := widget.NewEntry()
passLable := widget.NewLabel("PASSWORD")
passEntry := widget.NewPasswordEntry()
app_title := canvas.NewText(ApplicationTitle, color.NRGBA{0, 0x80, 0, 0xff})
app_title.TextSize = 24
// 5秒后改变颜色
go func() {
time.Sleep(5 * time.Second)
app_title.Text = ApplicationTitleToggle
app_title.Color = color.NRGBA{0x80, 0, 0, 0xff}
// 需要刷新才能显示
app_title.Refresh()
}()
c1 := container.New(layout.NewFormLayout(), userLable, userEntry, passLable, passEntry)
c := container.NewVBox(app_title, c1)
myWindow.SetContent(c)
myWindow.Resize(fyne.NewSize(300, 300))
myWindow.Show()
myApp.Run()
}
效果如下:
5秒后文本变色: