Skip to content
Advertisement

Julia Gtk Windows do not display outside REPL

I am trying to use Julia with the Gtk package outside the REPL.

Using this code:

Using Gtk.ShortNames
win = @Window("My Window")

in the REPL works, but the same code put in a test.jl file and using:

julia test.jl

in the command line does not work.

I have tried the method written here: https://github.com/JuliaLang/Gtk.jl

Using Gtk.ShortNames

win = @Window("gtkwait")

# Put your GUI code here

if !isinteractive()
    c = Condition()
    signal_connect(win, :destroy) do widget
        notify(c)
    end
    wait(c)
end

The code runs but no window appears.

If it’s any help, I’m on Manjaro Linux with 4.1 Linux Kernel and have both GTK2 and GTK3 librairies installed.

Advertisement

Answer

Your code, which is literally what the documentation says to do, doesn’t work for me either (Julia 0.4.0, Gtk.jl 0.9.2). Maybe the documentation is outdated.

What works is to use Gtk.gtk_main and Gtk.gtk_quit:

using Gtk.ShortNames
win = @Window("Hello")
signal_connect(win, :destroy) do widget
    Gtk.gtk_quit()
end
Gtk.gtk_main()

I don’t know if this is the “right” way, but it does work and is closer to how things work in GTK+’s C API (with gtk_main and gtk_main_quit).

Advertisement