 |
|
|
|
|
-bd => 2)->pack(-side => 'bottom',
-fill => 'x');
$f->Label(-textvariable => \$message,)->pack(-side => 'left'); |
|
|
|
|
|
|
|
|
This allows the label to grow and shrink within the frame as necessary, while the text sticks to the left side. If you've typed this short little example in and played with the strings bound to each widget, you might have noticed that the window will resize itself if the text assigned to $message is too long to display in the label. This can get annoying if your window is fairly small to begin with. There are two ways to deal with this: First, you can always use really short text strings, and second, you can tell the window to not resize when the label changes size. |
|
|
|
|
|
|
|
|
The drawbacks with each approach aren't too bad, and which one you pick just depends on the application you are working on. If you can make really short sentences that make sense, great. Telling the window to not resize is almost as easy, though-it is accomplished by adding one line to your program: |
|
|
|
 |
|
|
|
|
$mw->packPropagate(0); |
|
|
|
|
|
|
|
|
Using packPropagate will cause your window to not resize when a widget is placed inside the window (we first talked about packPropagate in Chapter 2, Geometry Management). This means that your window might not be showing all your widgets right away. You can deal with this by keeping it on until you get all your widgets in it, figuring out a good starting size for your window and using $mw->geometry(size) to request that size initially. (See Chapter 13, Toplevel Widgets, for info on the geometry method.) |
|
|
|
|
|
|
|
|
Label is a pretty boring widget, so there are only two methods available to change or get information on it: cget and configure. Both methods work for Label the same way they work for the Button widget. Please refer to Appendix A for the details on arguments and return values. |
|
|
|
|
|
|
|
|
Until now, the only input we know how to get from the user is a mouseclick on a button widget (Button, Checkbutton, or Radiobutton), which is handled via the -command option. Getting input from a mouseclick is useful, but it's also limiting. The entry widget will let the user type in text that can then be used in any way by the application. Here are a few examples of where you might use an entry widget: |
|
|
|
|
|
|
|
|
• In a database form that requires one entry per field (e.g., Name, Last name, Address) |
|
|
|
|
|
|
|
|
• In a software registration window that requires a serial number |
|
|
|
|