打包几何图形管理器将小部件打包为行或列。我们可以使用类似的选项填, 扩大和侧控制此几何图形管理器。
相比格经理包管理器在某种程度上受到限制, 但是在一些但很常见的情况下使用起来要容易得多:
- 将小部件放在框架中(或任何其他容器小部件), 并使其填满整个框架
- 将许多小部件彼此放在顶部
- 并排放置许多小部件
# Importing tkinter module
from tkinter import * from tkinter.ttk import *# creating Tk window
master = Tk()# cretaing a Fra, e which can expand according
# to the size of the window
pane = Frame(master)
pane.pack(fill = BOTH, expand = True )# button widgets which can also expand and fill
# in the parent widget entirely
b1 = Button(pane, text = "Click me !" )
b1.pack(fill = BOTH, expand = True )b2 = Button(pane, text = "Click me too" )
b2.pack(fill = BOTH, expand = True )mainloop()
输出如下:
文章图片
代码2:将小部件彼此并排放置。我们可以通过并排选项来实现。
# Importing tkinter module
from tkinter import *
# from tkinter.ttk import *# creating Tk window
master = Tk()# cretaing a Fra, e which can expand according
# to the size of the window
pane = Frame(master)
pane.pack(fill = BOTH, expand = True )# button widgets which can also expand and fill
# in the parent widget entirely
b1 = Button(pane, text = "Click me !" , background = "red" , fg = "white" )
b1.pack(side = TOP, expand = True , fill = BOTH)b2 = Button(pane, text = "Click me too" , background = "blue" , fg = "white" )
b2.pack(side = TOP, expand = True , fill = BOTH)b3 = Button(pane, text = "I'm also button" , background = "green" , fg = "white" )
b3.pack(side = TOP, expand = True , fill = BOTH)mainloop()
输出如下:
文章图片
代码3:
# Importing tkinter module
from tkinter import *
# from tkinter.ttk import *# creating Tk window
master = Tk()# cretaing a Fra, e which can expand according
# to the size of the window
pane = Frame(master)
pane.pack(fill = BOTH, expand = True )# button widgets which can also expand and fill
# in the parent widget entirely
b1 = Button(pane, text = "Click me !" , background = "red" , fg = "white" )
b1.pack(side = LEFT, expand = True , fill = BOTH)b2 = Button(pane, text = "Click me too" , background = "blue" , fg = "white" )
b2.pack(side = LEFT, expand = True , fill = BOTH)b3 = Button(pane, text = "I'm also button" , background = "green" , fg = "white" )
b3.pack(side = LEFT, expand = True , fill = BOTH)mainloop()
输出如下:
文章图片
【Python Tkinter中的pack()方法介绍】首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。
推荐阅读
- Python输出格式用法详细指南
- Python Pandas Series.str.strip()、lstrip()和rstrip()
- Python Pandas Series.to_numpy()用法介绍
- Python Pandas Series.truncate()用法介绍
- Python Pandas Series.value_counts()用法介绍
- Python Pandas时间戳date用法介绍
- python|使用Pytorch框架自己制作做数据集进行图像分类(二)
- 智汀家庭云和Home Assistant分别是如何接入HomeKit,两者之间有何不同()
- docker 常用命令总结