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

Tk::Listbox: 2 questions: performance and alignment

by busunsl (Vicar)
on Oct 10, 2002 at 09:36 UTC ( [id://204123]=perlquestion: print w/replies, xml ) Need Help??

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

I'm playing with Perl/Tk again and have two questions to which neither SuperSearch nor Google give any answers. (Perhaps because I used the wrong keywords)

The first question concerns performance of a Listbox, or rather a MListbox.
I've got a MListbox which is filled initially before packing. For 7500 entries (I know, this is much, and I will change the design) this takes about 17 seconds.
It is possible to refresh the contents after the widget is packed and now it takes over a minute to fill the MListbox.

I'm sure I've read somewhere, that you can somehow freeze a widget while you update it and show it afterwards, but I forgot where and how.
Any idea?

The next question concerns the alignment of the Listbox entries. They are left aligned by default.
How can I change this to right or center aligned?

TIA
busunsl

  • Comment on Tk::Listbox: 2 questions: performance and alignment

Replies are listed 'Best First'.
Re: Tk::Listbox: 2 questions: performance and alignment
by hiseldl (Priest) on Oct 10, 2002 at 14:01 UTC

    I'm sure I've read somewhere, that you can somehow freeze a widget while you update it and show it afterwards, but I forgot where and how.

    I'm not sure what you mean, do you want to store the data from the ListBox using Storable, for example?

    use Storable; tie $hashref, "Tk::Listbox", $lbox, {'ReturnType' => 'both'}; store $hashref, 'file'; ... $hashref = retrieve('file');

    Do you want to hide the widget? $listbox->packForget();

    Or, do you want to store the configuration of the widget?

    use Storable; @columninfo = $mlistbox->columnPackInfo(); store \@columninfo, 'file';

    The next question concerns the alignment of the Listbox entries. They are left aligned by default. How can I change this to right or center aligned?

    # "-anchor" specifies how the information in a widget (e.g. # text or a bitmap) is to be displayed in the widget. Must # be one of the values n, ne, e, se, s, sw, w, nw, or # center. For example, nw means display the information # such that its top-left corner is at the top-left corner # of the widget. $mlistbox->configure(-anchor => 'e'); # or 'center'

    --
    hiseldl
    What time is it? It's Camel Time!

      I'm not sure what you mean, do you want to store the data from the ListBox using Storable, for example?

      No, I didn't mean the freeze/thaw methods.

      Do you want to hide the widget?

      Yes, something like that. But with packForget and pack it's hard to put the widget into the same place. I thought there was another method.

      # "-anchor" specifies how the information in a widget (e.g.
      # text or a bitmap) is to be displayed in the widget.

      I know, but this doesn't work:

      my $MW = MainWindow->new(); $lb = $MW->Listbox()->pack(); $lb->configure(-anchor => 'e');
      Gives just:
      Bad option `-anchor' at yy.pl line 12.
      I also tried -justify without success.

        Is sounds like you need the grid layout manager instead, and the analagous method gridForget. Grid allows you to place everything in cells which gives you a finer level of control over the placement of your widgets.

        Check out this node for an example of how to use the grid layout manager. If you have any questions, leave a note here, or you can /msg hiseldl.

        --
        hiseldl
        What time is it? It's Camel Time!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-16 13:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found