# http://poe.perl.org/?POE_Cookbook/Tk_Interfaces # # This sample program creates a very simple Tk counter. Its interface # consists of three widgets: A rapidly increasing counter, and a # button to reset that counter. use warnings; use strict; # Tk support is enabled if the Tk module is used before POE itself. use Tk; use POE; # Create the session that will drive the user interface. POE::Session->create ( inline_states => { _start => \&ui_start, ev_count => \&ui_count, ev_clear => \&ui_clear, } ); # Run the program until it is exited. $poe_kernel->run(); exit 0; sub ui_start { my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ]; if(! defined($poe_main_window)) { die "\$poe_main_window not defined" }; $poe_main_window->Label( -text => "Counter" )->pack; $heap->{counter_widget} = $poe_main_window->Label( -textvariable => \$heap->{counter} )->pack; $poe_main_window->Button ( -text => "Clear", -command => $session->postback("ev_clear") )->pack; $poe_main_window->update; $kernel->yield("ev_count"); } # Handle the "ev_count" event by increasing a counter and displaying # its new value. sub ui_count { $_[HEAP]->{counter}++; $poe_main_window->update; sleep(1); $_[KERNEL]->yield("ev_count"); } # Handle the "ev_clear" event by clearing and redisplaying the # counter. sub ui_clear { $_[HEAP]->{counter} = 0; }