English 中文(简体)
Tk - Layout Widgets
  • 时间:2024-12-22

Tk - Layout Widgets


Previous Page Next Page  

Layout widgets are used to handle layouts for the Tk apppcation. 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 pst 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  -repef ridge -borderwidth 8 -padx 10 -pady 10
   -height 100 -width 100
frame .myFrame2 -background blue  -repef 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 −

Frame Widget Example Advertisements