Получить значение первого столбца из TK :: Tile :: Treeview в Ruby - PullRequest
0 голосов
/ 25 апреля 2018

Я пытаюсь получить значение первого столбца из элемента, извлеченного из древовидного списка, используя "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

1 Ответ

0 голосов
/ 09 мая 2018

Я не знаю, правильно ли я понимаю, что вы хотите сделать,

item.text

может быть решением.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...