#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Pane; use Tk qw(:eventtypes); my $mw = new MainWindow (-title=>" $0 MAIN"); my $phwin; my $display_label; my @to_show =('A'..'Z'); my $toggle_autoplay = 0; my $fr0 = $mw->Frame()->pack(); $fr0->Button( -text => "autoplay", -command => sub{$toggle_autoplay = 1; &autoplay}, #[\&autoplay, Ev $toggle_autoplay?$toggle_autoplay=0:$toggle_autoplay=1], )->pack(); # ok same behaviour of ->update #$mw->DoOneEvent(DONT_WAIT | ALL_EVENTS);# # the above without bitmask run but not at the right interval #also ok is: $mw->update; &secondary_win; MainLoop; ################################################################################ sub autoplay { while($toggle_autoplay){ $display_label->configure(-text=> shift @to_show); $phwin->update; #$phwin->DoOneEvent; sleep 1; #last if $phwin->waitVariable(\$toggle_autoplay); } } ################################################################################ sub secondary_win { # window does not exists if (! Exists($phwin)) { $phwin = $mw->Toplevel(); $phwin->title("SECONDARY"); $phwin->bind('' => sub { print "BEFORE: bind-p = $toggle_autoplay\n"; # THIS WORKS #if ($toggle_autoplay == 0){ # $toggle_autoplay = 1; #} #else{ # $toggle_autoplay = 0; #} # THE FOLLOWING DOES NOT WORKS! WHY? $toggle_autoplay == 0 ? $toggle_autoplay = 1 : $toggle_autoplay = 0 ; print "AFTER: bind-p = $toggle_autoplay\n"; }) } # window Exists else { $phwin->deiconify( ) if $phwin->state() eq 'iconic'; $phwin->raise( ) if $phwin->state() eq 'withdrawn'; } #my $scrolledframe = $phwin->Scrolled('Frame',-scrollbars => 'osoe')->pack(); $display_label = $phwin->Label(-text=>'SECONDARY')->pack; }