package Tcl::Tk; use strict; use Tcl; use Exporter; use DynaLoader; use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS); @ISA = qw(Exporter DynaLoader); $Tcl::Tk::VERSION = '0.75'; $::Tcl::Tk::DEBUG = 0; =head1 NAME Tcl::Tk - Extension module for Perl giving access to Tk via the Tcl extension =head1 SYNOPSIS use Tcl::Tk qw(:widgets :misc); $interp = new Tcl::Tk; label(".l", -text => "Hello world"); tkpack ".l"; MainLoop; Or use Tcl::Tk; $interp = new Tcl::Tk; $interp->label(".l", -text => "Hello world")->pack; $btn = $interp->button(".btn", -text => "test", -command => sub { $btn->configure(-text=>"[". $btn->cget('-text')."]"); })->pack; $interp->MainLoop; Or even perl/Tk compatible way: use Tcl::Tk qw(:perlTk); $mw = MainWindow->new; $mw->Label(-text => "Hello world")->pack; $btn = $mw->Button(-text => "test", -command => sub { $btn->configure(-text=>"[". $btn->cget('-text')."]"); })->pack; MainLoop; =head1 DESCRIPTION The Tcl::Tk submodule of the Tcl module gives access to the Tk library. It does this by creating a Tcl interpreter object (using the Tcl extension) and binding in all of Tk into the interpreter (in the same way that B or other Tcl/Tk applications do). Unlike perl-tk extension (available on CPAN), where Tcl+Tk+Tix are embedded into extension, this module connects to existing TCL installation. Such approach allows to work with most up-to-date TCL, and this automatically gives Unicode and pure TCL widgets available to application along with any widgets existing in TCL installation. As an example, Windows user have possibility to use ActiveX widgets provided by Tcl extension named "OpTcl", so to provide native Windows widgets. Please see and try to run demo scripts 'demo.pl', 'demo-w-tix.pl' and 'widgets.pl' in 'demo' directory of source tarball. =head2 Access to the Tcl and Tcl::Tk extensions To get access to the Tcl and Tcl::Tk extensions, put the commands near the top of your program. use Tcl; use Tcl::Tk; Another (and better) way is to use perlTk compatibility mode by writing: use Tcl::Tk qw(:perlTk); =head2 Creating a Tcl interpreter for Tk To create a Tcl interpreter initialised for Tk, use $i = new Tcl::Tk (DISPLAY, NAME, SYNC); All arguments are optional. This creates a Tcl interpreter object $i, and creates a main toplevel window. The window is created on display DISPLAY (defaulting to the display named in the DISPLAY environment variable) with name NAME (defaulting to the name of the Perl program, i.e. the contents of Perl variable $0). If the SYNC argument is present and true then an I call is done ensuring that X events are processed synchronously (and thus slowly). This is there for completeness and is only very occasionally useful for debugging errant X clients (usually at a much lower level than Tk users will want). =head2 Entering the main event loop The Perl method call $i->MainLoop; on the Tcl::Tk interpreter object enters the Tk event loop. You can instead do C or CMainLoop> if you prefer. You can even do simply C if you import it from Tcl::Tk in the C statement. Note that commands in the Tcl and Tcl::Tk extensions closely follow the C interface names with leading Tcl_ or Tk_ removed. =head2 Creating widgets As a general rule, you need to consult TCL man pages to realize how to use a widget, and after that invoke perl command that creates it properly. If desired, widgets can be created and handled entirely by Tcl/Tk code evaluated in the Tcl interpreter object $i (created above). However, there is an additional way of creating widgets in the interpreter directly from Perl. The names of the widgets (frame, toplevel, label etc.) can be imported as direct commands from the Tcl::Tk extension. For example, if you have imported the C