forked from go/golangs_learn
VIVIMAN
3 years ago
2 changed files with 97 additions and 1 deletions
@ -0,0 +1,95 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"fyne.io/fyne" |
|||
"fyne.io/fyne/container" |
|||
"time" |
|||
|
|||
"fyne.io/fyne/app" |
|||
"fyne.io/fyne/widget" |
|||
) |
|||
|
|||
func main() { |
|||
// demo01()
|
|||
// demo02()
|
|||
// demo03()
|
|||
demo04() |
|||
} |
|||
|
|||
// demo04 单元测试
|
|||
func demo04() { |
|||
a := app.New() |
|||
w := a.NewWindow("Hello Person") |
|||
|
|||
w.SetContent(container.NewVBox(makeUI())) |
|||
w.ShowAndRun() |
|||
} |
|||
func makeUI() (*widget.Label, *widget.Entry) { |
|||
out := widget.NewLabel("Hello world!") |
|||
in := widget.NewEntry() |
|||
|
|||
in.OnChanged = func(content string) { |
|||
out.SetText("Hello " + content + "!") |
|||
} |
|||
return out, in |
|||
} |
|||
|
|||
// demo03 设置窗口大小 - 控制主窗口
|
|||
func demo03() { |
|||
a := app.New() |
|||
w := a.NewWindow("Hello World") |
|||
|
|||
w.SetContent(widget.NewLabel("Hello World!")) |
|||
w.Show() |
|||
|
|||
w2 := a.NewWindow("Larger") |
|||
// 区别位置
|
|||
// w2.SetContent(widget.NewLabel("More content"))
|
|||
w2.SetContent(widget.NewButton("Open new", func() { |
|||
w3 := a.NewWindow("Third") |
|||
w3.SetContent(widget.NewLabel("Third")) |
|||
w3.Show() |
|||
})) |
|||
w2.Resize(fyne.NewSize(100, 100)) |
|||
w2.Show() |
|||
|
|||
a.Run() |
|||
} |
|||
|
|||
// demo02 设置窗口大小
|
|||
func demo02() { |
|||
a := app.New() |
|||
w := a.NewWindow("Hello World") |
|||
|
|||
w.SetContent(widget.NewLabel("Hello World!")) |
|||
w.Show() |
|||
|
|||
w2 := a.NewWindow("Larger") |
|||
w2.SetContent(widget.NewLabel("More content")) |
|||
w2.Resize(fyne.NewSize(100, 100)) |
|||
w2.Show() |
|||
|
|||
a.Run() |
|||
} |
|||
|
|||
// demo01 更新界面的内容
|
|||
func demo01() { |
|||
a := app.New() |
|||
w := a.NewWindow("Clock") |
|||
|
|||
clock := widget.NewLabel("") |
|||
updateTime(clock) |
|||
|
|||
w.SetContent(clock) |
|||
go func() { |
|||
for range time.Tick(time.Second) { |
|||
updateTime(clock) |
|||
} |
|||
}() |
|||
w.ShowAndRun() |
|||
} |
|||
|
|||
func updateTime(clock *widget.Label) { |
|||
formatted := time.Now().Format("Time: 03:04:05") |
|||
clock.SetText(formatted) |
|||
} |
Loading…
Reference in new issue