go get github.com/lxn/walk
go: missing Git command ...
You need to visit git-scm.com/downloads and install Git. If after installation its error did not disappear, you need to make sure that the path to Git is registered in% PATH%.gopad.go
file with the following contents: package main import ( . "github.com/lxn/walk/declarative" ) func main() { MainWindow{ Title: "GoPad", // MinSize: Size{600, 400}, // }.Run() }
build.bat
bat script with the following contents: go build -ldflags="-H windowsgui" pause
ldflags
key, but then the form would run along with the console in the background. Run our script and make sure that everything compiled correctly. But it is too early to launch the resulting .exe file. We need to create another file - manifest. Create a file gopad.exe.manifest
(instead of gopad.exe
should be the name of the resulting binary) with the following contents: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="SomeName" type="win32"/> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/> </dependentAssembly> </dependency> </assembly>
import ( "github.com/lxn/walk" . "github.com/lxn/walk/declarative" )
func main() { var edit *walk.TextEdit MainWindow{ Title: "GoPad", MinSize: Size{600, 400}, Layout: VBox{}, Children: []Widget{ TextEdit{AssignTo: &edit}, }, }.Run() }
MainWindow{ Title: "GoPad", MinSize: Size{600, 400}, Layout: VBox{}, Children: []Widget{ TextEdit{AssignTo: &edit}, HSplitter{ MinSize: Size{600, 30}, Children: []Widget{ PushButton{ Text: "Copy", }, PushButton{ Text: "Paste", }, PushButton{ Text: "Load", }, PushButton{ Text: "Save", }, }, }, }, }.Run()
PushButton{ Text: "Save", OnClicked: func() { // ... }, },
walk.Clipboard().SetText("text"); // walk.Clipboard().Text(); //
edit.Text(); // edit.SetText("text"); //
PushButton{ Text: "Copy", OnClicked: func() { walk.Clipboard().SetText(edit.Text()); }, }, PushButton{ Text: "Paste", OnClicked: func() { if text, err := walk.Clipboard().Text(); err == nil { edit.SetText(text) } }, },
edit
variable global. Let's create the readFromFile
function that loads text from the text file file.txt
into the field (do not forget that in the import
you need to add "io/ioutil"
): var edit *walk.TextEdit func readFromFile() { contents,_ := ioutil.ReadFile("file.txt") edit.SetText(string(contents)) }
func saveToFile() { ioutil.WriteFile("file.txt", []byte(edit.Text()), 0x777) }
PushButton{ Text: "Load", OnClicked: readFromFile, }, PushButton{ Text: "Save", OnClicked: saveToFile, },
package main import ( "github.com/lxn/walk" . "github.com/lxn/walk/declarative" "io/ioutil" ) var edit *walk.TextEdit func readFromFile() { contents,_ := ioutil.ReadFile("file.txt") edit.SetText(string(contents)) } func saveToFile() { ioutil.WriteFile("file.txt", []byte(edit.Text()), 0x777) } func main() { MainWindow{ Title: "GoPad", MinSize: Size{600, 400}, Layout: VBox{}, Children: []Widget{ TextEdit{AssignTo: &edit}, HSplitter{ MaxSize: Size{600, 30}, Children: []Widget{ PushButton{ Text: "Copy", OnClicked: func() { walk.Clipboard().SetText(edit.Text()); }, }, PushButton{ Text: "Paste", OnClicked: func() { if text, err := walk.Clipboard().Text(); err == nil { edit.SetText(text) } }, }, PushButton{ Text: "Load", OnClicked: readFromFile, }, PushButton{ Text: "Save", OnClicked: saveToFile, }, }, }, }, }.Run() }
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="SomeFunkyNameHere" type="win32"/> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/> </dependentAssembly> </dependency> </assembly>
go build -ldflags="-H windowsgui" pause
Source: https://habr.com/ru/post/205268/
All Articles