Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

TK::HList the best solution?

by z3d (Scribe)
on May 11, 2004 at 09:57 UTC ( #352377=perlquestion: print w/replies, xml ) Need Help??

z3d has asked for the wisdom of the Perl Monks concerning the following question:

Friends (and strangers :) ),
I'm trying my hand at writing a perl-tk app, mostly for the shere fun of learning it, but have hit a stumbling block that I could use some advise on. My app is pulling in data that I'd like to display in a column/row format, allowing the user to simply double click the row they want to launch a new window that does some more fancy work/processing. I like the way Tk::HList looks, and have kludged it to do the job I want, but I'm wondering if there's a better way, or if I'm perhaps not using it correctly (I've read the pods, I've abused the widgets demo where applicable, and I don't have the resources to purchase "Mastering Tk" atm).

Right now, I have a code block like:

my $hlist = $mw->Scrolled(qw/HList -columns 3 -width 70 -command main::launch_win/)->pack(qw/-expand yes -fill both/);
which works, albeit in an ugly fashion. Through newbie experimentation I see that it passes the $entryID to my sub, and I've cobbled together what I believe to be a bad hack that associates the $entryID to a key in a hash, from which I can pull the relevant pieces of data to determine which row was hit and move forward. But is there a better way? The ideal would be to double click a row and pass it a specific piece of data rather than relying on the $entryID pass - am I doing this wrong? For those that wonder, I've tried using $hlist->configure(-command => mysub($whatiwant)), but this resulted in the desired command being run immediately for every row returned (not desirable when the number of rows can be between 1 and a really really large number).

I confess that my thinking is a little too linear at times, so I don't immediately grok how to declare the command prior to having the (randomly) generated data available. Is there perhaps a better way to give the display I want with the functionality I need than by using Tk::HList?

Thank you all in advance for your time and thoughts.


"I have never written bad code. There are merely unanticipated features."

Replies are listed 'Best First'.
Re: TK::HList the best solution?
by eserte (Deacon) on May 11, 2004 at 10:15 UTC
    You can attach arbitrary data to HList entries by setting the -data option in add or entryconfigure. Then you can retrieve the data with $hlist->entrycget($entryID, "-data")

      Thank you for such a speedy response! Indeed, that is precisely what I needed. Never fails, I post what feels like a decent question and someone has the answer back in seconds :) Is there a discernible difference between $hlist->info(data, $entryID) and $hlist->entrycget($entryID, "-data"), or just different ways of pealing the same orange? (just curious, you don't have to humor my question at this point :) ).

      Thank you again,


      "I have never written bad code. There are merely unanticipated features."
        It's just another way to do it.
Re: TK::HList the best solution?
by gri6507 (Deacon) on May 11, 2004 at 19:10 UTC
    Yet another way to get around a grid-like arrangement is to use buttons and a grid positioning manager, where each button has a command associated with it.
      True - but i have four columns, with the number of rows being determined by how much is scraped off a website (this is a bugzilla tk front end I'm playing with if that explains it any better). The number of rows could be 3,or it could be 100's, and I didn't relish the idea of a button for each item in each row...bah :) 'Sides, HList has a potential use for a feature I'm thinking of to see multiple bugzilla servers/accounts at once (being able to break it out into, well, Horizontal Lists/trees).

      Update: ...which I guess means I just invalidated part of my original post :/ (though the problem with passing data, now understood, was legit)

      "I have never written bad code. There are merely unanticipated features."

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://352377]
Approved by jdtoronto
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2023-06-08 05:59 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (29 votes). Check out past polls.