=head1 NAME perl/Tk - Writing Tk applications in perl5. =for category Introduction =head1 DESCRIPTION This manual page is for beginners. It assumes you know some perl, and have got perl+Tk running. Please run the 'widget' demo before reading this text; it will teach you the various widget types supported by Tk. =head1 Some background Tk GUI programming is event-driven. (This may already be familiar to you.) In event-driven programs, the main GUI loop is outside of the user program and inside the GUI library. This loop will watch all events of interest, and activate the correct handler procedures to handle these events. Some of these handler procedures may be user-supplied; others will be part of the library. For a programmer, this means that you're not watching what is happening; instead, you are requested by the toolkit to perform actions whenever necessary. So, you're not watching for 'raise window / close window / redraw window' requests, but you tell the toolkit which routine will handle such cases, and the toolkit will call the procedures when required. =head1 First requirements Any perl program that uses Tk needs to include C. A program should also use C and the B<-w> switch to ensure the program is working without common errors. Any Tk application starts by creating the Tk main window. You then create items inside the main window, or create new windows, before starting the mainloop. (You can also create more items and windows while you're running.) The items will be shown on the display after you C them; more info on this later. Then you do a Tk mainloop; this will start the GUI and handle all events. That's your application. A trivial one-window example is show below: #! /usr/bin/perl5 -w use strict; use Tk; my $main = MainWindow->new; $main->Label(-text => 'Hello, world!')->pack; $main->Button(-text => 'Quit', -command => [$main => 'destroy'] )->pack; MainLoop; Please run this example. It shows you two items types also shown in the widget demo; it also shows you how items are created and packed. Finally, note the typical Tk style using C<-option> =E C pairs. =head1 Item creation Tk windows and widgets are hierarchical, S includes one or more others. You create the first Tk window using Cnew>. This returns a window handle, assigned to C<$main> in the example above. Keep track of the main handle. You can use any Tk handle to create sub-items within the window or widget. This is done by calling the Tk constructor method on the variable. In the example above, the C