gouser-interfacechild-processfyne

Go Fyne unable to show dialog


I am running a project in Go on vs code, when I run it, printing content outputs to the terminal. I want to be able to fork x children where each child process can present their own dialog and out put data to it. I found fyne is an easy UI for Go and when I run runApp() a small dialog appears. I can't figure out how to concurrently open multiple dialogs, resize them, and log/print text to them. Every child process should be able to print any text to their specific dialog at any time.

For some reason when main gets ran nothing happens, maybe I am using to go routine wrong.

package main

import (
   "bufio"
   "fmt"
   "log"
   "os"
   "fyne.io/fyne/v2/app"
   "fyne.io/fyne/v2/container"
   "fyne.io/fyne/v2/widget"
)

func main() {
   // Fork 3 child processes
   for i := 0; i < 3; i++ {
       go runApp()
   }
}

// Child process code
func runApp() {
   a := app.New()
   w := a.NewWindow("Hello")

   hello := widget.NewLabel("Hello Fyne!")
   w.SetContent(container.NewVBox(
       hello,
       widget.NewButton("Hi!", func() {
           hello.SetText("Welcome :)")
       }),
   ))

   w.ShowAndRun()
}

Solution

  • You can only run a single GUI app in a process. The way to do what you want is to launch the goroutines and show multiple windows from a single app. The app would be run at the end of your main() by calling a.Run() instead of w.ShowAndRun().

    See https://docs.fyne.io/started/windows.html