user interface – Second window should open and wait-ThrowExceptions

Exception or error:

I am trying following simple GUI code where the main window has only one button (exit). On clicking this button, a new window should open, it should stay open for 3 seconds and then it should close, followed by exiting of whole application:

package main
import (
    "github.com/andlabs/ui"
    "time"
    "os"
)
func main(){
    ui.Main(makeMainWin)
}
func makeMainWin(){
    var mainWindow = ui.NewWindow("Main Window", 50, 100, false)  
    var exitButton = ui.NewButton("Exit")
    exitButton.OnClicked( func (*ui.Button) {
        // call lastfn() before closing: this should display a new window for 3 seconds:
        lastfn()
    })
    mainWindow.SetChild(exitButton)
    mainWindow.OnClosing( func (*ui.Window) bool {
        // call lastfn() before closing: this should display a new window for 3 seconds:
        lastfn()
        return true
    })
    mainWindow.Show()
}
func lastfn(){
    // Create a window that displays "Pleas wait" and "Closing"
    var waitWin = ui.NewWindow("Please wait", 300, 50, false) 
    waitWin.SetChild(ui.NewLabel("Closing..."))
    waitWin.Show() // THIS IS NOT WORKING- NOW NEW WINDOW OPENS.
    time.Sleep(3000*time.Millisecond) // wait for 3 secs.
    waitWin.Destroy() // destroy window and exit.
    os.Exit(0)
}

However, on clicking the exit button, the application waits for 3 seconds and then exits. There is no opening of new window.

Where is the problem and how can it be solved? Thanks for your help.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *