Tk – Layout Widgets

  • Post author:
  • Post category:Tk
  • Post comments:0 Comments
Tk - Layout Widgets

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
1FrameContainer widget to hold other widgets.
2PlaceWidget to hold other widgets in specific place with coordinates of its origin and an exact size.
3PackSimple widget to organize widgets in blocks before placing them in the parent widget.
4GridWidget 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 −

Next Topic : Click Here

Leave a Reply