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

Re: perl tk bind callback

by converter (Priest)
on Oct 17, 2003 at 19:26 UTC ( #300117=note: print w/replies, xml ) Need Help??

in reply to perl tk bind callback

You can create your own class derived from Tk::Label and override the configure method.

#!/usr/bin/perl use warnings; use strict; use Tk; { package Tk::MyLabel; use Tk::widgets('Label'); @Tk::MyLabel::ISA = 'Tk::Label'; Tk::Widget->Construct('MyLabel'); sub configure { my ($cw, %args) = @_; if (my $bg = $args{-background} || $args{-bg}) { print "changing background to: $bg\n"; } $cw->SUPER::configure(%args); } } my (@color, $color) = qw(blue green); my $mw = tkinit; $mw->packPropagate(0); my $lab = $mw->MyLabel( -text => "foo", -background => $color[0], )->pack; my $b = $mw->Button( -text => 'Do it!', -command => sub { $color = $color ? 0 : 1; $lab->configure(-background => $color[$color]); } )->pack; $mw->bind('<Control-q>', sub { Tk::exit(0) }); MainLoop;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://300117]
[choroba]: Corion Nice
[Corion]: Hi choroba! I'm somewhat fond of this picture - I think it is Breaking Bad-style even though I haven't watched the series at all ;)
[Corion]: Hmmm - and now that I look at it, the gallery I'm using doesn't produce non-Javascript compatible links in the sense that hotlinking to an image will only work for Javascript enabled...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2017-02-27 08:30 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (377 votes). Check out past polls.