douhuang1973
douhuang1973
2019-08-21 13:11

如何声明ui.NewEntry数组?

  • user-interface
已采纳

I am trying to create a GUI with a series of text entry fields:

package main
import ("github.com/andlabs/ui")
func main() {
    ui.Main(makeMainWin)
}
func makeMainWin(){
    var entlist = []ui.NewEntry //Error here. How to declare an array of ui.NewEntry?
    var box = ui.NewVerticalBox()
    for i,_ := range [5]int{} {
        println(i)
        box.Append(ui.NewEntry(), false)
    }
    var mainWindow = ui.NewWindow("Hello", 200, 100, false)
    mainWindow.SetChild(box)
    mainWindow.OnClosing( func (*ui.Window) bool { 
               ui.Quit(); return true   } )
    mainWindow.Show()
}

However, there is error on var entlist = []NewEntry

I am not able to create an array of NewEntry components. I have tried []ui.NewEntry, []*ui.NewEntry, []ui.NewEntry() and []*ui.NewEntry()

Where is the problem and how can it be solved? Thanks for your help.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanben4771 duanben4771 2年前

    ui.NewEntry returns *Entry, therefore your slice should be declared as:

    var entlist []*ui.Entry
    
    点赞 评论 复制链接分享