Gtk.jl icon indicating copy to clipboard operation
Gtk.jl copied to clipboard

Please add an example how to use a checkbox

Open ufechner7 opened this issue 3 years ago • 3 comments

Using checkboxes is neither documented in the help, nor is there an example how to do that available. Please, add a simple example for a dialog with checkboxes without using Glade.

ufechner7 avatar Jul 30 '22 15:07 ufechner7

The following code works:

using Gtk.ShortNames, GtkObservables

# define the default values
OPTION_A = false
OPTION_B = false
finished = false 

cb1 = checkbox(OPTION_A, label="Option A")
cb2 = checkbox(OPTION_B, label="Option B")
btnOK = button(label="OK")

win = Window("Dialog", 200, 72) |> (bx = Box(:v))
push!(bx, cb1)
push!(bx, cb2)
push!(bx, btnOK)

function on_button_clicked(win)
    global OPTION_A, OPTION_B, finished, win
    OPTION_A = observable(cb1)[]
    OPTION_B = observable(cb2)[]
    destroy(win)
    finished = true
end
signal_connect(on_button_clicked, widget(btnOK), "clicked")

Gtk.showall(win)
while ! finished
    sleep(0.1)
end

println("Option A: $OPTION_A")
println("Option B: $OPTION_B")
nothing

But it depends on GtkObservables and is not using a modal Gtk Dialog. I would be glad if someone comes up with a better solution.

ufechner7 avatar Jul 31 '22 08:07 ufechner7

In the test dir there is the file gui.jl, which should bei more complete than the docs. There is an example on CheckButton.

tknopp avatar Jul 31 '22 09:07 tknopp

Thanks for pointing to the file gui.jl ! Nevertheless more examples would be useful.

ufechner7 avatar Jul 31 '22 09:07 ufechner7