Hi hudo,

I've had a lot of good luck using the Text and ROText widgets for this kind of thing.  Both of your requirements, sorting and displaying in different colors, are quite easy using either widget (but should be easy to do anyway, regardless of which widget you choose).

Here's a short example I've written to show you how to to sort items and display them in a ROText widget:

use strict; use warnings; use Tk; use Tk::ROText; # User-defined my $textfont = "Helvetica 12"; my @colors = qw( peachpuff lightyellow ); my @items = ( 'blue', 'orange', 'white', 'red', 'gray', 'yellow', 'purple', 'tan', 'pink', 'green', 'black', ); # Globals my @all_items = ( ); my $item_count = 0; # Main program my $mw = new MainWindow; my $f1 = $mw->Frame()->pack(-expand => 0, -fill => 'x'); my $f2 = $mw->Frame()->pack(-expand => 1, -fill => 'both'); my $ps = sub { $mw->destroy() }; my $b1 = button($f1, 'Exit', 'right', $ps, "Escape"); my $b2 = button($f1, 'Clear', 'left', sub { clear_all() }); my $b3 = button($f1, 'Insert', 'left', sub { insert_all() }); my $txt = $f2->Scrolled('ROText', -scrollbars => 'osoe')->pack(); insert_all(); MainLoop; # Subroutines sub button { my ($w, $text, $side, $psub, $bind) = @_; $bind ||= 0; $bind and $text .= " ($bind)"; my $btn = $w->Button(-bg => 'skyblue', -text => $text); if ($psub || 0) { $btn->configure(-command => $psub); $bind and $mw->bind("<$bind>" => sub { $btn->invoke() }); } $btn->pack(-side => $side); return $btn; } sub clear_all { # Delete all items in the Text widget @all_items = ( ); $txt->delete("1.0", "end"); $item_count = 0; } sub insert_all { # Delete the contents of the Text widget first $txt->delete("1.0", "end"); $item_count = 0; # Sort the items, adding each to the Text widget push @all_items, @items; my @sorted = sort @all_items; foreach (@sorted) { insert_item($_); } } sub insert_item { my ($text) = @_; my $tag = "item_" . ++$item_count; my $bg = $colors[$item_count % @colors]; $txt->tagConfigure($tag, -font => $textfont, -background => $bg); $txt->insert("end", "$text\n", $tag); }

The trick is that, each time you click on the "Insert" button, it clears the ROText widget first, then adds the list of colors into the full list @all_items, sorts the full list, and displays it.

The multiple colors are achieved by keeping track of how many items have been added to the list (with $item_count), and displaying one or the other of the colors in @colors.

Hopefully, the above example will give you some ideas about how to get started.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: list overview sorted and colored rows by liverpole
in thread list overview sorted and colored rows by hudo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.