For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > September 2005 > Tk::Scale: is there a way to set the slider's color?









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 Tk::Scale: is there a way to set the slider's color?
Wolfram Humann

2005-09-06, 7:56 am

As far as I can see, the scale's slider (unless active) takes the
-background color, but changing that also changes the background for the
area surrounding the trough. Is there any option (or workaround) for
changing the slider's color without changing other colors inside the scale?
zentara

2005-09-07, 7:57 am

On Tue, 06 Sep 2005 12:44:15 +0200, Wolfram Humann
<w.n.humann.removethis@agilent.com> wrote:

>As far as I can see, the scale's slider (unless active) takes the
>-background color, but changing that also changes the background for the
>area surrounding the trough. Is there any option (or workaround) for
>changing the slider's color without changing other colors inside the scale?


There are alot of options for color, and they don't always do what you
think.

-activebackground -background -foreground
-highlightback-ground -troughcolor
-highlight-color

Can you post a minimal example, and show what colors are not
doing what you think they should?



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

2005-09-07, 7:57 am

-----Original Message-----
From: zentara
Sent: 07.09.2005 10:56
> On Tue, 06 Sep 2005 12:44:15 +0200, Wolfram Humann
> <w.n.humann.removethis@agilent.com> wrote:
>
>
>
>
> There are alot of options for color, and they don't always do what you
> think.
>
> -activebackground -background -foreground
> -highlightback-ground -troughcolor
> -highlight-color
>
> Can you post a minimal example, and show what colors are not
> doing what you think they should?


Well, I tried all of these ...
Here's some minimal examples:

perl -MTk -e"tkinit->Scale(-background => 'red')->pack;MainLoop"
gives me a red slider (good) but also a red area around the trough (bad)

perl -MTk -e"tkinit->Scale(-highlightbackground=>'red')->pack;MainLoop"
gives a red outer edge of the widget :-(

perl -MTk -e"tkinit->Scale(-activebackground => 'red')->pack;MainLoop"
affects only the slider (hooray) but it's red only when the mouse is
over the slider (booooo!)

So my question remains: can I have a red (or any other color) slider but
everything else in standadrd color?

Thanks for any answers,
Wolfram
zentara

2005-09-08, 7:57 am

On Wed, 07 Sep 2005 11:44:27 +0200, Wolfram Humann
<w.n.humann.removethis@agilent.com> wrote:

>
>perl -MTk -e"tkinit->Scale(-activebackground => 'red')->pack;MainLoop"
>affects only the slider (hooray) but it's red only when the mouse is
>over the slider (booooo!)
>
>So my question remains: can I have a red (or any other color) slider but
>everything else in standadrd color?
>
>Thanks for any answers,
>Wolfram


As usually is the case, when you need some customization, use
the Canvas. :-)

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

my $dx;

my $mw = MainWindow->new;
$mw->geometry("500x60");

my $width = 500;
my $height = 30;
my $min = 20;
my $mid = 40;
my $max = 80;

my $canvas = $mw->Canvas(-width => $width, -height =>$height,
-bg => 'black',
-borderwidth => 3,
-relief => 'sunken',
)->pack;

my $red_adj = $canvas->createLine($min, 0, $min, $height,
-fill => 'red',
-width => 10,
-tags => ['move'],
);

my $blue_adj = $canvas->createLine($mid, 0, $mid, $height,
-fill => 'lightblue',
-width => 10,
-tags => ['move'],
);

my $green_adj = $canvas->createLine($max, 0, $max, $height,
-fill => 'green',
-width => 10,
-tags => ['move'],
);


$canvas->bind('move', '<1>', sub {&mobileStart();});
$canvas->bind('move', '<B1-Motion>', sub {&mobileMove();});
$canvas->bind('move', '<ButtonRelease>', sub {&mobileStop();});

my $bframe = $mw->Frame()->pack(-expand =>'x');

my $closebutton = $bframe->Button(-text => 'Exit',
-command => sub{ exit })->pack(-side=>'right');

MainLoop;

sub mobileStart {
my $ev = $canvas->XEvent;
$dx = 0 - $ev->x;
$canvas->raise('current');
print "START MOVE->$dx\n";
}

sub mobileMove {
my $ev = $canvas->XEvent;
$canvas->move('current', $ev->x + $dx, 0 );

$dx = 0 - $ev->x;
print 'Value->', -$dx ,"\n";
}

sub mobileStop{&mobileMove;}

__END__

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

2005-09-08, 7:57 am

-----Original Message-----
From: zentara
Sent: 08.09.2005 13:20
>
> As usually is the case, when you need some customization, use
> the Canvas. :-)
>
> #!/usr/bin/perl
> [...]
> __END__
>


Yeah, nice demonstration of how easy you can do things with a canvas!
But I really don't want to reinvent Tk::Scale. Getting just the most
important things like limits, "-from"/"-to", ticks and labels right
would mean substantial extra work.

Thanks for the demo,
Wolfram
zentara

2005-09-09, 6:57 pm

On Thu, 08 Sep 2005 13:39:13 +0200, Wolfram Humann
<w.n.humann.removethis@agilent.com> wrote:

>Yeah, nice demonstration of how easy you can do things with a canvas!
>But I really don't want to reinvent Tk::Scale. Getting just the most
>important things like limits, "-from"/"-to", ticks and labels right
>would mean substantial extra work.
>


The same problem faces the Scrollbars on scrolled widegts. It's
impossible to change the slider color. You can change the trough
color, and the active color, but normally it's the washed out grey.

Just to mention it, but Perl/Gtk2 lets you set the colors, thru it's
themes.


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