1overview(3) User Contributed Perl Documentation overview(3)
2
3
4
6 Tk - An overview of an Object Oriented Tk8 extension for perl5
7
9 "use Tk;"
10
11 "$main = MainWindow-E<gt>new();"
12
13 "$widget = $main-E<gt>I<Widget>(...);"
14
15 "$widget-E<gt>pack(...);"
16
17 ...
18
19 "MainLoop;"
20
22 In writing the perl Tk extension, the goals were to provide a complete
23 interface to the latest production version of John Ousterhout's Tk,
24 while providing an Object Oriented interface to perl code.
25
27 The package is composed of three loosely connected parts:
28
29 pTk - Converted Tk source
30 The pTk sub-directory is a copy of the C code of Tk8.x, modified to
31 allow use by languages other than the original Tcl. (The pTk can
32 be read as 'perl' Tk or 'portable' Tk, depending on your
33 sensibilities.)
34
35 Tk to Perl 'Glue'
36 The top level directory provides Tk.xs and tkGlue.c which provide
37 the perl-callable interfaces to pTk
38
39 Perl code for 'Widget' Classes
40 The Tk sub-directory contains the various perl modules that
41 comprise the "Classes" that are visible to Tk applications.
42
43 The "major" widgets such as Tk::Text are actually in separate
44 directories at the top level (e.g. Text/* for Tk::Text) and are
45 dynamically loaded as needed on platforms which support perl5's
46 DynaLoader.
47
49 package Tk; - the 'base class'
50 All the "command names" documented in Tcl/Tk are made to look like
51 perl sub's and reside in the Tk package. Their names are all lower
52 case. Typically there are very few commands at this level which
53 are called directly by applications.
54
55 package Tk::Widget; - the 'Widget class'
56 There are no actual objects of the Tk::Widget class; however all
57 the various Tk window "widgets" inherit from it, and it in turn
58 inherits all the core Tk functions from Tk.
59
60 Tk::Widget provides various functions and interfaces which are
61 common to all Widgets.
62
63 A widget is represented to perl as a blessed reference to a hash.
64 There are some members of the hash which are private to Tk and its
65 tkGlue code. Keys starting with '.' and of the form
66 /_[A-Z][A-Za-z_]+_/ (i.e. starting and ending in _ and with first
67 char after _ being upper case) should be considered reserved to Tk.
68
69 Tk::Button, Tk::Entry, Tk::Text ...
70 There is one class for each of the "Tk" widget item types. Some of
71 them like Tk::Frame do very little indeed, and really only exist so
72 that they can be derived from or so that focus or menu traversal
73 can discover the "kind" of window being processed.
74
75 Other classes, Tk::Text for example, provide a lot of methods used
76 with Tk's "bind" to provide a rich keyboard/mouse interface to the
77 widgets' data.
78
79 These widget classes also include conversions of the Tcl code for
80 event bindings, keyboard focus traversal, menu bars, and menu
81 keyboard traversal. All the Tcl functions have been converted, but
82 the names have changed (systematically) and they have been split up
83 between the various classes in what I hope is an appropriate
84 manner. Name changes are normally: dropping initial tk_ as the Tk-
85 ness is implicit in the Tk:: prefix, and similarly dropping say
86 Menu from the name if it has been moved the Tk::Menu class. Thus
87 'proc tkMenuNextEntry' becomes 'sub NextEntry' in the Tk::Menu
88 package.
89
90 Tk::Image
91 This does for Tk8.x's "images" what Tk::Widget does for widgets.
92 Images are new to Tk8.x and the class structure is not mature
93 either.
94
95 There are three sub-classes Tk::Bitmap, Tk::Pixmap and Tk::Photo.
96
97 It is possible to create dynamic or auto-loaded image types
98 inherited from Tk::Image for other image types or photo formats
99 (e.g. support for TIFF format).
100
101 Composite Widgets
102 A composite is some kind of 'frame' with subwidgets which give it
103 useful behaviour. Tk::Dialog is an example of a composite widget
104 classes built from the basic Tk ones. It is intended that user
105 code should not need to be aware that a particular class is a
106 composite, and create and configure such widgets in the same manner
107 as any other kind. The configure mechanism and the methods of the
108 class manipulate the subwidgets as required.
109
110 Composite widgets are implemented via Tk::Frame and multiple
111 inheritance. The two 'frame' base classes Tk::Frame and
112 Tk::Toplevel include the additional class Tk::Derived in their
113 inheritance. Tk::Derived provides methods to allow additional
114 configure options to be defined for a widget.
115
116 A Composite widget is typically defined as derived from Tk::Frame
117 or Tk::Toplevel (e.g. Tk::Dialog).
118
119
120
121perl v5.12.0 2010-05-13 overview(3)