Fyne错误:在没有启动任何应用程序的情况下尝试访问当前Fyne应用程序



我一直在努力找出导致这个错误的原因。。。也许只是我,但也许你能看到我做不到的。希望你能帮我一把。

每当我运行我的代码时,它都会给出这个错误

Fyne错误:在未启动时尝试访问当前Fyne应用程序

转到/pkg/mod/fyne.io/fyne/v2@v2.2.3/app.go:92

知道吗?这是代码。它运行*

// GoMark project main.go
// Version 1.3
package main
import (
"fmt"
"image/color"
"log"
"os"
"runtime"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
var text = widget.NewMultiLineEntry() //Text entry
var textTitle = widget.NewLabel("")
var preview = widget.NewRichTextFromMarkdown("") //Preview side
var myWindow fyne.Window
var down_dir = ""
var filePath = "" // THIS WILL NOT EDIT PRESET!!! Look further down...
var savename = ""
var savenametxt = ""
var myApp = app.New()
func main() {
myWindow = myApp.NewWindow("GoMark 1.3")
// - - - Text editor / Preview - - -
textTitle.SetText("UNSAVED DOCUMENT")
left := container.NewBorder(nil, nil, nil, nil, text)
middle := container.NewHSplit(left, preview)
text.OnChanged = func(string) { //When someting is written or canged in the text entry, update with this function
preview.ParseMarkdown(text.Text)
}
// - - - END - - -
// - - - TOP SECTION - - -
//Line creation
line := canvas.NewLine(color.Black)
line.StrokeWidth = 4
savename := widget.NewEntry()
savename.SetPlaceHolder("ABC123")
//- - - Settings toolbar - - -
settings := widget.NewToolbar(
widget.NewToolbarAction(theme.ContentClearIcon(), func() {
dialog.ShowConfirm("Do you want to clear document?", "", callback, myWindow)
}),
widget.NewToolbarSeparator(),
widget.NewToolbarAction(theme.FolderNewIcon(), func() {
log.Println("Save as Doc")
dialog.ShowFileSave(DownloadDirectory, myWindow)
}),
widget.NewToolbarAction(theme.DocumentSaveIcon(), func() {
log.Println("Save Doc")
form_savename := widget.NewFormItem("", savename)
form := dialog.NewForm("Save Name to S:", "Save", "Cancel", []*widget.FormItem{form_savename}, func(b bool) {
if b == true {
fmt.Println("Save selected")
savenametxt = savename.Text
SaveToS(myWindow)
savename.SetText(savenametxt)
}
}, myWindow)
form.Resize(fyne.NewSize(400, 200))
form.Show()
}),
)
//Combiner
top := container.NewBorder(nil, line, nil, settings, textTitle)
// - - - END - - -
//Run the main fyne window
main := container.NewBorder(top, nil, nil, nil, middle)
myWindow.Resize(fyne.NewSize(1200, 800))
myWindow.SetContent(main)
myWindow.ShowAndRun()
}
//Clear text confirmation
func callback(yes bool) {
fmt.Println("Running Callback")
if yes == true {
fmt.Println("Text CLEAR")
clean()
} else {
fmt.Println("Text STAY")
}
}
//Clear text box and preview
func clean() {
text.Text = ""
preview.ParseMarkdown(text.Text)
text.Refresh()
textTitle.Text = "UNSAVED DOCUMENT"
textTitle.Refresh()
dialog.ShowInformation("Text has been cleared", "", myWindow)
}
//Choose a Download folder
func DownloadDirectory(savedir fyne.URIWriteCloser, err error) {
fmt.Println("Dialog")
fmt.Println(savedir.URI())
}
//- - - Save to S: - - -
func SaveToS(myWindow fyne.Window) {
if runtime.GOOS == "Windows" {
filePath = "S:\TMP\DocMove" //EDIT DIR PRESET FOR WINDOWS
filePath = filePath + "\"
} else {
filePath = "/mnt/s/TMP/DocMove" // EDIT DIR PRESET FOR LINUX
filePath = filePath + "/"
}
fmt.Println(runtime.GOOS)
file, errC := os.Create(filePath + savenametxt + ".md")
if errC != nil {
dialog.ShowError(errC, myWindow)
fmt.Println(errC)
return
} else {
_, errWriting := file.Write([]byte(text.Text))
if errWriting != nil {
dialog.ShowError(errWriting, myWindow)
fmt.Println(errWriting)
return
} else {
textTitle.SetText(savenametxt)
dialog.ShowInformation("Sucess", savenametxt+" Has been saved", myWindow)
fmt.Println(filePath + savenametxt + ".md")
}
}
}

您正试图在启动fyne应用程序之前创建小部件。

这个订单没有给我任何错误:

var down_dir = ""
var filePath = "" // THIS WILL NOT EDIT PRESET!!! Look further down...
var savename = ""
var savenametxt = ""
var myApp = app.New()
var text = widget.NewMultiLineEntry() //Text entry
var textTitle = widget.NewLabel("")
var preview = widget.NewRichTextFromMarkdown("") //Preview side
var myWindow fyne.Window

相关内容

  • 没有找到相关文章

最新更新