Open realicing opened 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()
Please search the issues for Synchronize.
Synchronize
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()
}
func loop() { for true { msg := <- ch
} 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")
}