Tkinter Frame(框架): 框架构件在某种友好的方式进行分组和组织的其他部件的过程中是非常重要的。它就像一个容器,这是负责安排其他部件的位置
框架构件在某种友好的方式进行分组和组织的其他部件的过程中是非常重要的。它就像一个容器,这是负责安排其他部件的位置.
它采用在屏幕上的矩形区域组织布局,并提供这些部件的填充。一个框架也可以用来作为一个基础类,以实现复杂的构件,.
语法:
这里是一个简单的语法来创建这个widget:
w = Frame ( master, option, ... )
参数:
-
master: 这代表了父窗口.
-
options: 下面是这个小工具最常用的选项列表。这些选项可以作为键 - 值对以逗号分隔.
Option | Description |
---|---|
bg | The normal background color displayed behind the label and indicator. |
bd | The size of the border around the indicator. Default is 2 pixels. |
cursor | If you set this option to a cursor name (arrow, dot etc.), the mouse cursor will change to that pattern when it is over the checkbutton. |
height | The vertical dimension of the new frame. |
highlightbackground | Color of the focus highlight when the frame does not have focus. |
highlightcolor | Color shown in the focus highlight when the frame has the focus. |
highlightthickness | Thickness of the focus highlight. |
relief | With the default value, relief=FLAT, the checkbutton does not stand out from its background. You may set this option to any of the other styles |
width | checkbutton的默认宽度取决于所显示的图像或文字的大小。您可以设置此选项的字符数和checkbutton的,总是有许多字符的空间. |
例子:
自行尝试下面的例子:
from Tkinter import * root = Tk() frame = Frame(root) frame.pack() bottomframe = Frame(root) bottomframe.pack( side = BOTTOM ) redbutton = Button(frame, text="Red", fg="red") redbutton.pack( side = LEFT) greenbutton = Button(frame, text="Brown", fg="brown") greenbutton.pack( side = LEFT ) bluebutton = Button(frame, text="Blue", fg="blue") bluebutton.pack( side = LEFT ) blackbutton = Button(bottomframe, text="Black", fg="black") blackbutton.pack( side = BOTTOM) root.mainloop()
这将产生以下结果: