Skip to content

Instantly share code, notes, and snippets.

@ddrscott
Last active October 31, 2017 14:35
Show Gist options
  • Select an option

  • Save ddrscott/21c69dc02641ca1cbacd4a5802126088 to your computer and use it in GitHub Desktop.

Select an option

Save ddrscott/21c69dc02641ca1cbacd4a5802126088 to your computer and use it in GitHub Desktop.
Demo of basic Tk::Tile::Treeview
require 'tk'
# set up fake data
data = ('a'..'z').map do |i|
('a'..'z').map {|j| i + j}
end
headings = data.shift
root = TkRoot.new { title 'TREE' }
root.minsize = [400, 300]
tree = Tk::Tile::Treeview.new(root)
tree['padding'] = [0, 0, 0, 0]
tree['columns'] = headings.join(' ')
font = Tk::Tile::Style.lookup('Tree', 'font')
headings.each do |heading|
tree.heading_configure(heading, text: heading)
tree.column_configure(heading, width: TkFont.measure(font, heading))
end
data.each do |row|
tree.insert(nil, :end, values: row)
end
tree.pack(fill: 'both', expand: 1)
Tk.mainloop
@ddrscott
Copy link
Author

ddrscott commented Oct 31, 2017

Should work for Ruby <= 2.3.4

curl https://gist.githubusercontent.com/ddrscott/21c69dc02641ca1cbacd4a5802126088/raw/666841a93126a795a37fade00fc6ba9e75c0795e/tk_table.rb | ruby

Screenshot:
screen shot 2017-10-31 at 9 34 05 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment