| 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
|