Introductory perl/Tk, based on the 2 March 1999 dc perlmongers meeting.
Author: Raul Miller <moth@magenta.com>
This is an initial draft which focusses on the example scripts written for that meeting.
Note that these were written on an windows NT system, so are
missing the #!/usr/bin/perl line -- add it in if you need it.
[For the meeting, they were all invoked using the:
perl filename syntax.]
proto.pluse Tk; $w= MainWindow->new; MainLoop | ![]() |
|
button
use Tk;
$w= MainWindow->new;
$w->Button(-text=>"Quit", -command=>sub{exit})->pack;
MainLoop
| ![]() |
|
labeluse Tk; $w= MainWindow->new; $w->Label(-text=>"This is some text")->pack; MainLoop | ![]() |
|
checkuse Tk; $w= MainWindow->new; $w->Checkbutton(-text=>"AAAA", -variable=>\$aaaa)->pack; $w->Checkbutton(-text=>"WWWW", -variable=>\$wwww)->pack; $w->Label(-textvariable=>\$aaaa)->pack; $w->Label(-textvariable=>\$wwww)->pack; MainLoop; | ![]() |
|
check1use Tk; $w= MainWindow->new; $w->Checkbutton(-text=>"AAAA", -variable=>\$aaaa)->pack; $w->Checkbutton(-text=>"WWWW", -variable=>\$wwww)->pack; $aaaa=1; $w->Label(-textvariable=>\$aaaa)->pack; $w->Label(-textvariable=>\$wwww)->pack; MainLoop; | ![]() |
|
radiouse Tk; $w= MainWindow->new; $w->Radiobutton(-text=>"AAAA", -variable=>\$aaaa, -value=>1)->pack; $w->Radiobutton(-text=>"WWWW", -variable=>\$aaaa, -value=>2)->pack; $w->Label(-textvariable=>\$aaaa)->pack; MainLoop; | ![]() |
|
radio1
use Tk;
$w= MainWindow->new;
$w->Radiobutton(-text=>"AAAA",
-variable=>\$aaaa,
-value=>1)->pack(-anchor=>'w');
$w->Radiobutton(-text=>"WWWW",
-variable=>\$aaaa,
-value=>2)->pack(-anchor=>'w');
$w->Label(-textvariable=>\$aaaa)->pack;
MainLoop;
| ![]() |
|
entry
use Tk;
$w= MainWindow->new;
$w->Label(-textvariable=>\$text)->pack;
$entry= $w->Entry->pack;
$entry->bind('
| ![]() |
|
browse
use Tk;
$w= MainWindow->new;
$w->Label(-textvariable=>\$text)->pack;
$entry= $w->BrowseEntry(-variable=>\$text)->pack;
map {$entry->insert('end',$_)} 'this', 'is', 'a', 'test';
MainLoop
| ![]() |
|
checkhelp
use Tk;
$w= MainWindow->new;
$help= $w->Balloon;
$c1= $w->Checkbutton(-text=>"AAAA",
-variable=>\$aaaa)->pack;
$help->attach($c1, -msg=> "This check button says AAAA");
$c2= $w->Checkbutton(-text=>"WWWW",
-variable=>\$wwww)->pack;
$help->attach($c2, -msg=> "This check button says WWWW");
$label_1= $w->Label(-textvariable=>\$aaaa)->pack;
$help->attach($label_1, -msg=> "see AAAA, above");
$label_2= $w->Label(-textvariable=>\$wwww)->pack;
$help->attach($label_2, -msg=> "see WWWW, above");
MainLoop;
| ![]() |
|
dialog
use Tk;
$w= MainWindow->new;
print $w->Dialog(-text=>'hey, there!',
-title=>'hey',
-buttons=>['a','b','c']
)->Show;
print "\n";
| ![]() |
|
fileselectuse Tk; $w= MainWindow->new; print $w->FileSelect->Show; print "\n"; | ![]() |
|
messuse Tk; $w= MainWindow->new; $w->Message(-text=>"This is some text")->pack; MainLoop | ![]() |
|
t
use Tk;
$w= MainWindow->new;
$t= $w->Text->pack;
$t->insert('end', q{
This is some text
it goes on for a while
...
...
....
the end});
MainLoop
| ![]() |
|
t1
use Tk;
$w= MainWindow->new;
$t= $w->Scrolled('Text')->pack;
$t->insert('end', q{
This is some text
it goes on for a while
...
...
....
the end});
MainLoop
| ![]() |
|