Last active
October 31, 2017 14:35
-
-
Save ddrscott/21c69dc02641ca1cbacd4a5802126088 to your computer and use it in GitHub Desktop.
Demo of basic Tk::Tile::Treeview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should work for Ruby <= 2.3.4
Screenshot:
