Using Gtk can I make a dialog pop up where I enter some text?

Hi!

Basically I want a small GUI to open up where it is just possible to write a line and then save that string. Is that possible?

This is how far I am right now:

## Make small interface
win = GtkWindow("Save File",300,50)

ent = GtkEntry()
set_gtk_property!(ent,:text,"Insert Filename")

push!(win,ent)
Gtk.showall(win)

str = get_gtk_property(ent,:text,String)

image

Now I would like it to register my input when I press “Enter”

EDIT2:

function get_filename_gui()
    win = GtkWindow("Save File",300,50)

    ent = GtkEntry()
    set_gtk_property!(ent,:text,"Insert Filename")

    push!(win,ent)
    Gtk.showall(win)

    str = ""
    if isinteractive()
        c = Condition()
        signal_connect(win, "key-press-event") do widget, event
            if event.keyval == 65293 #Enter
                str = get_gtk_property(ent,:text,String)
                notify(c)
            end
        end
        wait(c)
    end

    Gtk.destroy(win)

    return str
end

The code above does the trick, “using Gtk”

Kind regards

Have a look at GtkReactive:
https://juliagizmos.github.io/GtkReactive.jl/stable/reference.html#Input-widgets-1

There’s also an input_dialog function in Gtk.jl that does pretty much that :

https://github.com/JuliaGraphics/Gtk.jl/blob/17bfda1ea78a511cd39d58de56c09cadd93262fb/src/windows.jl#L96

See also :

https://juliagraphics.github.io/Gtk.jl/latest/manual/filedialogs/

1 Like

I want to second what Jonathon suggested. I have not used input_dialog myself but I am using info_dialog and ask_dialog quite a bit, the later allows for getting true/false decisions. You can also design a custom dialog, as is basically shown in the implementation of the input_dialog. The important bit is that you are using GtkMessageDialog or GtkDialog as the the basis since this will give you the most important behaviors the you were missing in your first example.

Thanks @jonathanBieler and @tobias.knopp!

I will look into this when I need to do it more “correctly”. I am quite happy I atleast got it to work on my own, even if the code is not optimal.

Kind regards