Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

questions about TK

Status
Not open for further replies.

perlcoder

Programmer
Jul 1, 2001
16
0
0
US
I want to write an exe program using TK. Any idea where do i start? Also when you write programs using TK, do you put the usual #!/usr/bin/perl line? And do you save that as .pl or .exe?
 
First,
use Perl with the Tk module to build your application.

Second,
use one of the available tools for converting a Perl program into an executable. There are several tools that will do it. has 'perlApp' as part of their Perl developer's Kit. There is also 'perl2exe' from Either of these will produce Win flavored stand-alone executables. I have used perlApp some. It works as advertised with 2 caveats:
1 - Usually, you must explicitly 'use' each widget in your code.
2 - It will not recursively bundle dlls. It will get the first level of required dlls, but, if one dll requires a second, perlApp won't bundle the second level into the executable.

Be aware that PerlApp produced executables are large. My most recent app was 20k of text and turned into almost 2 megs of executable file. It did, however, compress down to about 900k.

The following is a very simple and useless example of using Tk to open some windows, lay in a label, and build a couple of buttons.

HTH

Code:
#!perl
use strict;
use Tk;

my $mw1 = MainWindow->new;
$mw1->configure(-title=>"perl GUI",
                -background=>'light grey');
$mw1->geometry('400x245+300+100');

my $fr1 = $mw1->Frame(  -relief=>'raised',
            -borderwidth=>2,
            -background=>'light grey')  
    ->pack(-side=>'top', -fill=>'x');
            
$fr1->Button(-text=>'Exit', 
             -command=>sub{exit})  
    ->pack(-side=>'right');
    
$mw1->Label(-text=>'Use this button to pop another window',
            -background=>'light grey')  
    ->pack(-side=>'top', -fill=>'x');

my $fr2 = $mw1->Frame(-relief=>'raised',
            -borderwidth=>2,
            -background=>'light grey')  
    ->pack(-side=>'top');

$fr2->Button(-text=>'Pop another window', 
             -command=>\&new_win )
    ->pack(-side=>'bottom');
MainLoop;
#----------------------------------------------------------
sub new_win
{
my $mw2 = MainWindow->new;
$mw2->configure(-title=>"perl GUI",-background=>'light grey');
$mw2->geometry('100x100+300+100');
$mw2->Button(-text=>'OK', -command=>sub{ $mw2->destroy } )
        ->pack(-side=>'bottom');
}
Please use descriptive titles and check the FAQs.
And, beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top