Layout widgets are used to handle layouts for the Tk application. Frame widget is used group other widgets and place, pack, and grid are layout manager to give you total control over your adding to windows. The list of available layout widgets are as shown below −
Sr.No. | Widgets & Description |
---|---|
1 | Frame
Container widget to hold other widgets. |
2 | Place
Widget to hold other widgets in specific place with coordinates of its origin and an exact size. |
3 | Pack
Simple widget to organize widgets in blocks before placing them in the parent widget. |
4 | Grid
Widget to nest widgets packing in different directions. |
A simple Tk example is shown below for layout widgets −
#!/usr/bin/wish frame .myFrame1 -background red -relief ridge -borderwidth 8 -padx 10 -pady 10 -height 100 -width 100 frame .myFrame2 -background blue -relief ridge -borderwidth 8 -padx 10 -pady 10 -height 100 -width 50 pack .myFrame1 pack .myFrame2
When we run the above program, we will get the following output −