Gtk example help

New to programming and Julia. Trying out an example with the GTk package. It runs OK calling the .jl file under the julia REPL. include(“gtktest.jl”). Window comes up and when I press the button i get the "button was pressed " response. When I try to run the script under the windows command prompt c:\ julia gtktest.jl nothing happens. The path is good . it’s not a “path” issue. I placed the file in the same directory as the julia.exe executable.
using Gtk

win = GtkWindow(“My First Gtk.jl Program”, 400, 200)

b = GtkButton(“Click Me”)
push!(win,b)

function on_button_clicked(w)
println(“The button has been clicked”)
end
signal_connect(on_button_clicked, b, “clicked”)

showall(win)

From the Non REPL Usage · Gtk.jl documentation, your program should wait for the window to be closed if you wish to run the program outside of the Julia REPL, using this piece of code:

if !isinteractive()
    c = Condition()
    signal_connect(win, :destroy) do widget
        notify(c)
    end
    @async Gtk.gtk_main()
    wait(c)
end

Essentially, this will create a Condition object that the program will “wait” until it is notified when the window is closed. This will keep the program running instead of immediately closing.

1 Like

Thanks