Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Tk/Perl Command

by pg (Canon)
on Mar 20, 2003 at 18:13 UTC ( #244670=note: print w/replies, xml ) Need Help??

in reply to Tk/Perl Command

Tk has limitations, but not this one;-).

In this case, you have to pass the widget into your sub. For example:
#!/usr/bin/perl use Tk; use strict; use constant BUTTON_WIDTH => 20; my $mw = new MainWindow(title => "demo"); my $button = $mw->Button(text => "color", width => BUTTON_WIDTH) ->pack; $mw->Button(text => "red", width => BUTTON_WIDTH, command => sub {change_color($button, "red")}) ->pack; $mw->Button(text => "green", width => BUTTON_WIDTH, command => sub {change_color($button, "green")}) ->pack; MainLoop; sub change_color { my ($widget, $color) = @_; $widget->configure(background => $color); }

Replies are listed 'Best First'.
Re: Re: Tk/Perl Command
by aquarium (Curate) on Mar 21, 2003 at 02:12 UTC
    I agree with "pg", pass the references of your widgets to fact, that's how tk programs become more modular, so you're not playing around with global vars everywhere. You only need to pass the reference of a widget and a subroutine has access (via configure) to all of its' properties and methods. Chris
There We Go!
by ok (Scribe) on Mar 20, 2003 at 18:49 UTC
    That's what I was looking for, I still have some problems as I shouldn't be using textvarriable I now see and I had my button too high up in my script to be catching the code. Thanks again!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://244670]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2022-08-16 11:10 GMT
Find Nodes?
    Voting Booth?

    No recent polls found