Tags Perl
I'm now implementing a data viewer in Perl/Tk (on windows) at work. I have a binary file which has some structure (records), that should be displayed as a table, and I should be able to roll through the records.

This GUI is simple, bar the table. I've never had to make a table in Tk before, and wasn't sure how to go about it. I found the Tk::Table module... in its "Bugs/Issues" section they warned about bad performance when the table is too big. After all, each cell in this table is a widget, and each widget is a window...

I tried using Tk::Table, and it indeed came out too slow. My table is about 40 x 5 elements, that is 200 widgets, which is indeed quite many. It's a real pity, as Tk::Table is a very nice widget, with cool options like fixed rows (ones that don't scroll), which is useful for headings.

With Tk::Table turning out not good enough, I started looking for alternatives. That is, other widgets or rolling-my-own table with a Canvas.

HList looked like it has some abilities that may be of help, but eventually it turned out not to be good as a table. It's nice as a hierarchical display, e.g. for files and directories. Other widgets that Google searches and Perlmonks suggested also weren't good. It appeared that implementing my own table with a Canvas was the only way to go.

So, yesterday I did it. I have some experience with columnar data on a Canvas, for my Perlines and Perlbombs (Minesweeper clone) games, where the play area is a grid.

I divided the Canvas into columns and rows, and wrote a function that placed some text in a cell. It's easy to attach a scrollbar to a Canvas, and even to set a scroll delta so that scrolling will shift between discrete rows. However, for the heading (unscrollable) I had to throw in another Canvas.

All in all it works nicely, and is definitely faster than the Tk::Table version. After all, a Canvas is just a single widget, though many items in it add some complexity, they are not windows by themselves.