Home > Archive > PerlTk > July 2007 > how to change background in all children widgets
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 |
how to change background in all children widgets
|
|
| Petr Vileta 2007-07-12, 10:03 pm |
| I have frame, labels in this frame and 2 button for change frame background
color. I want to change background color too in all labels in frame. Can
anybody tell me how to modify my code?
#!/usr/bin/perl
use strict;
use Tk;
use Tk::Frame;
use Tk::Label;
use Tk::Button;
my $mw = MainWindow->new(-title => 'test 1');
my $fr=$mw->Frame(-relief=>'raised',-bd=>3)
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'x');
$fr->Label(-text => 'Label 1',-justify=>'left',-anchor=>'nw')
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'none');
$fr->Label(-text => 'Label 2',-justify=>'left',-anchor=>'nw')
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'none');
$mw->Button(-text=>'Red', -command=> sub { $fr->configure(-bg=>'red') } );
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'none');
$mw->Button(-text=>'Green', -command=> sub {
$fr->configure(-bg=>'green') } );
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'none');
MainLoop;
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
| |
| Ch Lamprecht 2007-07-12, 10:03 pm |
| Petr Vileta wrote:
> I have frame, labels in this frame and 2 button for change frame
> background color. I want to change background color too in all labels in
> frame. Can anybody tell me how to modify my code?
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new(-title => 'test 1');
my $fr=$mw->Frame(-relief=>'raised',-bd=>3)
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'x');
$fr->Label(-text => 'Label 1',-justify=>'left',-anchor=>'nw')
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'none');
$fr->Label(-text => 'Label 2',-justify=>'left',-anchor=>'nw')
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'none');
$mw->Button(-text=>'Red',
-command=> sub { $_->configure(-bg=>'red')
for $fr->Descendants,$fr} )
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'none');
$mw->Button(-text=>'Green',
-command=> sub { $_->configure(-bg=>'green')
for $fr->Descendants,$fr } )
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'none');
MainLoop;
HTH,Christoph
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
| |
| Petr Vileta 2007-07-12, 10:03 pm |
| Ch Lamprecht wrote:
> $mw->Button(-text=>'Red',
> -command=> sub { $_->configure(-bg=>'red')
> for $fr->Descendants,$fr} )
Huh, great. Thanks a lot.
Can you tell me please where this "Descendant" is described? I see it first
time in my life :-)
I have ActiveState Perl and I not found this word anywhere in html or pod
files.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
| |
| Colin Tuckley 2007-07-12, 10:03 pm |
| Petr Vileta wrote:
> Can you tell me please where this "Descendant" is described?
Try Googling for "perl-tk Descendants", among other refs I found
http://www.perltk.org/index.php?opt...id=19&Itemid=28
The book "Mastering Perl/Tk" which is the bible of perl-tk also talks about
it in Chapter 14.
regards,
Colin
--
Colin Tuckley | colin@tuckley.org | PGP/GnuPG Key Id
+44(0)1903 236872 | +44(0)7799 143369 | 0x1B3045CE
It is well known that Discworld trolls loose intelligence as they warm up.
Does this mean that a particularly hot headed troll would be a lava lout?
| |
| Ch Lamprecht 2007-07-12, 10:03 pm |
| Petr Vileta wrote:
> Can you tell me please where this "Descendant" is described? I see it
> first time in my life :-)
Hello,
It was discussed in this group some w s ago ;)
http://groups.google.de/group/comp....b8068948044c188
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
| |
| Petr Vileta 2007-07-12, 10:03 pm |
| Ch Lamprecht wrote:
> Petr Vileta wrote:
>
>
> Hello,
>
> It was discussed in this group some w s ago ;)
>
I found a little hack how to do the same effect.
------- file test1.pl ----------
#!/usr/bin/perl
use strict;
use Tk;
use Tk::Frame;
use Tk::Label;
use Tk::Button;
my $mw = MainWindow->new(-title =>'test 1');
our $bg=$mw->cget(-background);
my $fr=$mw->Frame(-relief=>'raised',-bd=>3)
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'x');
########### this is the hack ##############
$fr->{ConfigSpecs}->{-background}->[0]->[1]='DESCENDANTS';
#####################################
$fr->Label(-text => 'Label 1',-justify=>'left',-anchor=>'nw')
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'none');
$fr->Label(-text => 'Label 2',-justify=>'left',-anchor=>'nw')
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'none');
$mw->Button(-text=>'Red',-command=> sub {$fr->configure(-bg=>'red')})
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'x');
$mw->Button(-text=>'Green',-command=> sub {$fr->configure(-bg=>'green')})
->pack(-side=>'top',-anchor=>'w',-expand=>'no',-fill=>'x');
MainLoop;
------- end of file test1.pl ----------
Is there a better way?
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
|
|
|
|
|