lxn / walk

A Windows GUI toolkit for the Go Programming Language
Other
6.86k stars 887 forks source link

I want to send msg to window from a another goruntine,but get error #359

Open realicing opened 6 years ago

realicing commented 6 years ago

package main

import ( "github.com/lxn/walk" . "github.com/lxn/walk/declarative" "fmt" "time" ) var outTE *walk.TextEdit var ch = make(chan string) func main() { go sendMsg()

go loop()
OpenWindow(outTE)

}

func loop() { for true { msg := <- ch

    fmt.Println("-----"+msg)

    outTE.AppendText("手机:"+msg+"\r\n")
}

} func sendMsg() { time.Sleep(6 time.Second) ch <- "msg" } func OpenWindow(outTE walk.TextEdit){ var inTE walk.TextEdit var mw walk.MainWindow font := Font{PointSize: 20} MainWindow{ AssignTo: &mw, Title: "聊天窗口", MinSize: Size{1200, 800}, Layout: VBox{}, Children: []Widget{ HSplitter{ Children: []Widget{ TextEdit{AssignTo: &outTE, Font: font, VScroll: true, ReadOnly: true}, TextEdit{AssignTo: &inTE, Font: font, HScroll: true,}, }, }, PushButton{ Text: "发送", OnClicked: func() { input := inTE.Text() if len(input) == 0 { inTE.SetFocus() } else { outTE.AppendText("电脑:"+input+"\r\n")

                    inTE.SetText("")
                    inTE.SetFocus()
                }

            },
        },
    },
}.Run()

}

lxn commented 6 years ago

Please search the issues for Synchronize.