Julia 中 Gtk 单选按钮的回调
Callbacks of Gtk Radio Buttons in Julia
我正在尝试恢复我的旧代码,它在 Julia 中使用了单选按钮。但是,回调似乎不起作用(类似于复选框和按钮的回调 do 起作用)。这是一个最小的例子:
using Gtk
function test()
win = GtkWindow("Radio Button Test")
vbox = GtkBox(:v)
push!(win, vbox)
choices = ["first", "second", "third", "fourth"]
radios = [GtkRadioButton(choice) for choice in choices]
set_gtk_property!(radios[1], :active, true)
for r in radios
set_gtk_property!(r, :group, radios[1])
signal_connect(r, "toggled") do _
warn_dialog("Changed to: $(choices[findfirst(radios, r)])")
end
push!(vbox, r)
end
showall(win)
nothing
end
我做错了什么?
更新:我已经更新到最新版本(Julia 1.4.1 和 Gtk 1.1.3),但问题仍然存在,即当我点击单选按钮时似乎没有调用回调函数。
这不是真正的问题 - 问题出在回调函数上:findfirst
不能再这样使用了,所以出现了(不可见的)错误。
将回调更改为
warn_dialog("Changed to: $(get_gtk_property(r, :label, AbstractString))")
它按预期工作。
我正在尝试恢复我的旧代码,它在 Julia 中使用了单选按钮。但是,回调似乎不起作用(类似于复选框和按钮的回调 do 起作用)。这是一个最小的例子:
using Gtk
function test()
win = GtkWindow("Radio Button Test")
vbox = GtkBox(:v)
push!(win, vbox)
choices = ["first", "second", "third", "fourth"]
radios = [GtkRadioButton(choice) for choice in choices]
set_gtk_property!(radios[1], :active, true)
for r in radios
set_gtk_property!(r, :group, radios[1])
signal_connect(r, "toggled") do _
warn_dialog("Changed to: $(choices[findfirst(radios, r)])")
end
push!(vbox, r)
end
showall(win)
nothing
end
我做错了什么?
更新:我已经更新到最新版本(Julia 1.4.1 和 Gtk 1.1.3),但问题仍然存在,即当我点击单选按钮时似乎没有调用回调函数。
这不是真正的问题 - 问题出在回调函数上:findfirst
不能再这样使用了,所以出现了(不可见的)错误。
将回调更改为
warn_dialog("Changed to: $(get_gtk_property(r, :label, AbstractString))")
它按预期工作。