如何在Ruby Tk中动态更改组合框中的值

时间:2013-05-09 12:28:40

标签: ruby combobox refresh tk

这个想法非常简单:我有2个组合框。第二个应该根据第一个的选择重新确定其值。

# combobox 1:
$shape = TkVariable.new
$combobox_1 = Tk::Tile::Combobox.new(parent) { textvariable $shape; values ['IPE', 'HEA']}

# combobox 2:
$size = TkVariable.new
$combobox_2 = Tk::Tile::Combobox.new(parent) { textvariable $size; values $size_list}

# action
$combobox_1.bind("<ComboboxSelected>") {
  case $shape
  when 'IPE' then $size_list = [80, 100, ...]
  when 'HEA' then $size_list = [90, 130, ...]
  end
  }

但没有任何反应。组合框2似乎没有意识到它的价值已被改变。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

这不起作用,您使用此变量创建组合框,但更改组合框不会更改组合框。

我想你要找的是set

when 'IPE' then $combobox_2.values([80, 100, ...])