在Ruby中从TK::Tile::Treeview检索第一列值

在Ruby中从TK::Tile::Treeview检索第一列值,ruby,tk,Ruby,Tk,我尝试使用“item.get(“#0”)”从树视图检索的项目中检索第一列的值,但出现了以下错误“RuntimeError:无法设置显示列#0”。此方法适用于其他列。 有人能帮忙找出解决办法吗 问候,, 马克 下面是一个独立的示例代码: require 'tk' require 'tkextlib/tile' $root = TkRoot.new $frame = Tk::Tile::Frame.new($root) $tree = Tk::Tile::Treeview.new($frame)

我尝试使用“item.get(“#0”)”从树视图检索的项目中检索第一列的值,但出现了以下错误“RuntimeError:无法设置显示列#0”。此方法适用于其他列。 有人能帮忙找出解决办法吗

问候,, 马克

下面是一个独立的示例代码:

require 'tk'
require 'tkextlib/tile'
$root = TkRoot.new
$frame = Tk::Tile::Frame.new($root)
$tree = Tk::Tile::Treeview.new($frame)

$tree['columns'] = ['action_text','action_description']
$tree.column_configure("#0", :width => 100)
$tree.heading_configure("#0", :text => 'la 1er colonne')
$tree.column_configure('action_text', :width => 100, :anchor => 'center')
$tree.heading_configure('action_text', :text => 'Text')

$tree.column_configure('action_description', :width => 100, :anchor => 'w')
$tree.heading_configure('action_description', :text => 'Description')

# Inserted at the root, program chooses id:
$tree.insert('', 'end', :id => 'widgets', :text => 'Widget Tour')

# Same thing, but inserted as first child:
$tree.insert('', 0, :id => 'gallery', :text => 'Applications')

# Treeview chooses the id:
item = $tree.insert('', 'end', :text => 'Tutorial')

# Inserted underneath an existing node:
$tree.insert( 'widgets', 'end', :text => 'Canvas')
$tree.insert( item, 'end', :text => 'Tree')
$tree.insert('', 2, :text => 'tata')
$tree.insert('', 'end', :text => 'envolee', :values => ['le centre', 'la description'])

$frame.grid(:column => 0, :row => 0, :sticky => 'nsew') {padding "3 3 12 12"}
$tree.grid(:column => 0, :row => 0, :sticky => 'nsew')

TkGrid.columnconfigure($root, 0, :weight => 1)
TkGrid.rowconfigure($root, 0, :weight => 1)
TkGrid.columnconfigure($frame, 0, :weight => 1)
TkGrid.rowconfigure($frame, 0, :weight => 1)

def create_action
 item = $tree.selection_get[0]
 puts item
 puts "ID:" 
 puts item.id
 puts "Index:" 
 puts item.index
 puts "action_text:"
 puts item.get('action_text')
 puts "1:"
 puts item.get('#1')
 puts $tree.get(item.id, '#0')
 puts "0:"
 puts item.get("#0")
end

$tree.bind("Double-1") { create_action }
Tk.mainloop

我不知道我是否完全明白你想做什么

item.text
也许是个解决办法