Go GUI框架Fyne学习6_FileOpen
使用方法
a := app.New()
w := a.NewWindow("WordSentenceTool")
full := make([]byte, 0)
// 匿名实现
dialog.ShowFileOpen(func(f fyne.URIReadCloser, e error) {
b := make([]byte, 1024)
for {
_, err := f.Read(b)
full = append(full, b...)
if err == io.EOF {
break
}
}
fmt.Println(full)
defer f.Close()
}, w)
// 变量实现
file := dialog.NewFileOpen(func(f fyne.URIReadCloser, e error) {
b := make([]byte, 1024)
for {
_, err := f.Read(b)
full = append(full, b...)
if err == io.EOF {
break
}
}
fmt.Println(full)
defer f.Close()
}, w)
file.Show()
回调参数——fyne.URIReadCloser
// URIReadCloser represents a cross platform data stream from a file or provider of data.
// It may refer to an item on a filesystem or data in another application that we have access to.
type URIReadCloser interface {
io.ReadCloser
URI() URI
}
fyne实现了io.ReadCloser接口中的读取和关闭方法。
uri类型,可以返回各种形式的路径。