#!/usr/bin/perl # Simple Tk GUI. # Implements a sample Tk application. # Derived from # http://poe.perl.org/?POE_Cookbook/Tk_Interfaces # (which was written by Rocco Caputo and used # with permission). # Copyright 2004 by Rocco Caputo. Free software. # Same terms as Perl itself. Have fun! use warnings; use strict; use Tk; use POE; POE::Session->create( inline_states => { _start => \&handle_start, ev_count => \&handle_count, ev_clear => \&handle_clear, } ); POE::Kernel->run(); exit 0; sub handle_start { $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; $_[KERNEL]->yield("ev_count"); } sub handle_count { $_[HEAP]->{counter}++; $_[KERNEL]->yield("ev_count"); } sub handle_clear { $_[HEAP]->{counter} = 0; }