For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > November 2004 > displaying text into a progressbar









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author displaying text into a progressbar
Andre Bartsch

2004-11-26, 9:02 am

Hello, how can I display text in the middle of the progressbar. I'd like to
display the current value of the progress bar in percent. I created a text
widget into a progress bar widget but this solution is not satisfiable to
me.

In this solution the text widget has (of course) its own color. It would
be better if the text widget would have the color of the progressbar
widget.

The best way would be an text option for the progressbar or a corresponding
method. But I assume there isn't one.

--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/m2/
zentara

2004-11-26, 4:08 pm

On Fri, 26 Nov 2004 11:26:05 +0100, "Andre Bartsch"
<andre.bartsch@siemens.com> wrote:

>Hello, how can I display text in the middle of the progressbar. I'd like to
>display the current value of the progress bar in percent. I created a text
>widget into a progress bar widget but this solution is not satisfiable to
>me.
>
>In this solution the text widget has (of course) its own color. It would
>be better if the text widget would have the color of the progressbar
>widget.
>
>The best way would be an text option for the progressbar or a corresponding
>method. But I assume there isn't one.


Your best bet is just to put a label above or below the actual
progressbar, and display the text percentage. If you pack them right
they will look like a composite widget. :-) Or you could try to
make a Derived widget, it shouldn't be too hard.

Look at Tk::ActivityBar, it is already a Derived Progressbar, you could
hack it to include a Label in it.

Otherwise:

#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::ProgressBar;

my $mw = MainWindow->new();

my $pf = $mw->Frame()->pack();

my $p = $pf->ProgressBar(
-troughcolor => 'black',
-fg => 'lightgreen',
-blocks => 1,
-width => 20,
-length => 200,
-from => 0,
-to => 100,
-variable => \( my $foo ),
)->pack(-side =>'right');

my $l1 = $pf->Label(-text => '%',
-bg => 'black',
-fg => 'green',
)->pack(-side => 'right');

my $l2 = $pf->Label(-textvariable => \$foo,
-bg => 'black',
-fg => 'green',
-width => 3,
)->pack(-side => 'right');

$mw->Button( -text => 'Quit',
-command => sub { exit }
)->pack;


$foo = 0;
$mw->repeat( 100, sub { $foo = ( $foo + 1 ) % 100 } );

MainLoop;
__END__


--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com