1.6. Creating Widgets

All widgets are created in the same basic fashion, with only a few exceptions. Each widget must have a parent widget to watch over it as it is created and keep track of it while it exists in the application. When you create an application, you'll have a central window that will contain other widgets. Usually, that window will be the parent of all the widgets inside it and any other windows you create in your application. You are creating an order to the widgets so the communication between child and parent widgets can happen automatically without any intervention from you once you set it all up.

Assuming that the $parent widget already exists, the generic usage when you create widget Widgettype is as follows:

$child = $parent->Widgettype( [ -option => value, . . . ] );

Note that the variables that store the widgets are scalars. Actually, they are references to widget objects, but you don't need to know that right now. If you aren't familiar with the object-oriented programming in Perl, using the -> between the $parent and Widgettype invokes the method Widgettype, from the $parent object. It makes the $parent related to the child $child. As you might guess, the $parent becomes the parent of the widget being created. A parent can have many children, but a child can only have one parent. That's pretty much all there is to assigning children to their parents.

When you invoke the Widgettype method, there are usually configuration parameters that you send to set ...

Get Learning Perl/Tk now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.