📜  Tk-布局小部件

📅  最后修改于: 2020-10-16 06:33:52             🧑  作者: Mango


布局小部件用于处理Tk应用程序的布局。框架小部件用于对其他小部件进行分组,而布局,打包和网格是布局管理器,可让您完全控制添加到窗口中的过程。可用的布局小部件列表如下所示-

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.

下面是布局小部件的一个简单的Tk示例-

#!/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

当我们运行上面的程序时,我们将获得以下输出-

框架小部件示例