in reply to Re: Updating concatenated text on a Menubutton
in thread Updating concatenated text on a Menubutton

(Updated) I certainly agree with ar0n that tie is the way to go-- unless that looks too complicated for the case at hand.I still think the best way would be to build something similar to an If you don't want to do that, you might try an accessor method. That way you can trap the calls that set the bits and update the display variable whenever the bits get set. But I tried to do something like making the -textvariable an anonymous sub to no avail. I ended up with debugging code in my label.
#!/usr/bin/perl -w use strict; use Tk; my $Foo = 'x'; my $Bar = 'y'; my $foobar = setfoobar(); my $mw = Tk::MainWindow->new(); my $entry = $mw->Label( -textvariable => \$foobar, )-> pack( -expand => 'y', ); my $foo_button = $mw->Button( -text => "FOO", -command => sub { flip( $Foo );} )->pack(); my $bar_button = $mw->Button( -text => "BAR", -command => sub { flip( $Bar );} )->pack(); MainLoop(); sub flip { $_[0] = ( $_[0] eq 'x' ) ? 'y' : 'x'; setfoobar(); } sub setfoobar { $foobar = $Foo . $Bar; }