Browse | Submit A New Snippet | Create A Package

 

popup_tk.pl

Type:
Full Script
Category:
Other
License:
GNU General Public License
Language:
Perl
 
Description:
program which shows a message for some seconds on the screen. Requires perl/tk

Versions Of This Snippet::

peter bauer
Snippet ID Download Version Date Posted Author Delete
6981.02012-11-22 20:20peter bauer

Download a raw-text version of this code by clicking on "Download Version"

 


Latest Snippet Version: :1.0

#!/usr/bin/perl -w
# Autor: peter bauer
# peba@inode.at

use Tk;

if ($ARGV[0])  {
$param = $ARGV[0];
$main = MainWindow->new;
$param = convert($param);  #convert
$main->Label('-text' => $param, '-height' => '5',
             '-width' => '30',
             '-font' => ['Courier', '48','bold'])->pack();
$main->after (10000,sub {endapp()});	#end the program after 10 seconds 
#center ($main);       #position the window somewhere in the middle
    
MainLoop;
}

sub endapp {
#print "exiting\n";
exit;
}

sub center {
  my $win = shift;

  $win->withdraw;   # Hide the window while we move it about
  $win->update;     # Make sure width and height are current

  # Center window
  my $xpos = int(($win->screenwidth  - $win->width ) / 3);
  my $ypos = int(($win->screenheight - $win->height) / 2);
  $win->geometry("+$xpos+$ypos");
  $win->deiconify;  # Show the window again
}

sub convert {
  my $chars = shift;
  my $len = length $chars;
  my $count = 0;
  my $char = "";
  my $spec = "";
  my $res  = "";
  
  while ($count < $len) {
          $char = substr($chars,$count,1); 
          if ($char eq "%") { 
           #print "found special char\n";
           $spec = substr ($chars,$count+1,2);
           #print "spec:",$spec;
           $count = $count + 3;
	   $res = $res . chr(hex($spec));
	   }
	   else {
	   $res = $res . $char;
	   $count = $count +1;  
           }
	}
	return $res;
}
		

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..