#!/usr/bin/env perl use strict; use warnings; use constant { TIMER_INTERVAL => 1_000, NOTIFY_PERIOD => 10_000, }; use Tk; my $mw = MainWindow::->new(); $mw->configure(-title => 'Status Notification Manager'); $mw->geometry('320x60+50+100'); #$mw->withdraw(); my $status = _get_status(); my $last_status = $status; my $status_msg; _set_status_msg($status, \$status_msg); my $timer_id = $mw->repeat(TIMER_INTERVAL, sub { $status = _get_status(); if ($status ne $last_status) { $last_status = $status; _set_status_msg($status, \$status_msg); my $notify_panel = $mw->Toplevel(); $notify_panel->geometry('200x50-0-0'); $notify_panel->overrideredirect(1); my $msg_F = $notify_panel->Frame( )->pack( -side => 'left', -fill => 'both', -expand => 1, ); $msg_F->Label( -text => $status_msg, -anchor => 'w', )->pack( -side => 'left', -padx => 5, ); my $x_F = $notify_panel->Frame( )->pack( -side => 'left', -fill => 'y', ); my $x_B = $x_F->Button( -text => 'X', -bg => '#ff0000', -bd => 1, -relief => 'flat', -anchor => 'ne', -command => sub { if (Exists($notify_panel)) { $notify_panel->destroy(); } }, )->pack(); $notify_panel->raise(); $notify_panel->bell(); $mw->after(NOTIFY_PERIOD, sub { if (Exists($notify_panel)) { $notify_panel->destroy(); } }); } return; }); $mw->Button( -text => 'Exit', -command => sub { $timer_id->cancel(); exit; }, )->pack(-pady => 5); my $status_bar_F = $mw->Frame( )->pack(-side => 'bottom', -fill => 'x'); $status_bar_F->Label( -textvariable => \$status_msg, -anchor => 'w', -relief => 'sunken', )->pack(-fill => 'x'); MainLoop; sub _get_status { join ':', map sprintf('%02d', $_), (localtime())[2,1]; } sub _set_status_msg { my ($status, $msg_ref) = @_; $$msg_ref = 'Status: ' . $status; return; } #### ken@titan ~/tmp $ ./pm_11126974_tk_status_change_2.pl & [1] 618 ken@titan ~/tmp $ kill -HUP 618 ken@titan ~/tmp $ [1]+ Hangup ./pm_11126974_tk_status_change_2.pl ken@titan ~/tmp $