|
|
|
|
|
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 up the widget and interactions within the application. The configuration parameters will occur in pairs: an option and associated value. You will see options similar to -text, -state, or -variable. Notice that the options all start with a dash. Even with the dash, they are really just strings that are labels to indicate the next value to come in the list. Usually, it is not necessary to put quotation marks around the options because Perl is smart enough to recognize them as strings. However, if you are using the -w switch, Perl may complain about an option that it thinks is not text. You can stick quotes around all your options all the time to avoid this, but it shouldn't be necessary. The option names are always all lowercase (except in a few very rare cases, which are noted as we cover them). |
|
|
|
|
|
|
|
|
Options are specified in list form like this: |
|
|
|
 |
|
|
|
|
(-option => value, -option => value, -option => value) |
|
|
|
|
|
|
|
|
Don't be fooled by the funny-looking =>; it is just a different way of saying "comma." In fact, you could use just the commas and not the => notation, that is: |
|
|
|
 |
|
|
|
|
(-option, value, -option, value, -option, value) |
|
|
|
|