惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
月光博客
月光博客
AI
AI
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
CXSECURITY Database RSS Feed - CXSecurity.com
WordPress大学
WordPress大学
GbyAI
GbyAI
L
Lohrmann on Cybersecurity
O
OpenAI News
Schneier on Security
Schneier on Security
P
Palo Alto Networks Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
W
WeLiveSecurity
L
LINUX DO - 最新话题
人人都是产品经理
人人都是产品经理
S
Security Affairs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
Arctic Wolf
Recorded Future
Recorded Future
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
GRAHAM CLULEY
N
Netflix TechBlog - Medium
TaoSecurity Blog
TaoSecurity Blog
C
Check Point Blog
Scott Helme
Scott Helme
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Vercel News
Vercel News
The Hacker News
The Hacker News
Y
Y Combinator Blog
Latest news
Latest news
SecWiki News
SecWiki News
Hugging Face - Blog
Hugging Face - Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Cisco Blogs
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
宝玉的分享
宝玉的分享
L
LINUX DO - 热门话题

博客园 - 箫笛

Tkinter - Button 组件 Tkinter - Label 组件 Tkinter - tk 变量 Tkinter - 事件与绑定 Tkinter - 核心概念 Tkinter - 快速开始 Tkinter - 介绍 Python 编程 - 条件表达式 Python 编程 - 星号下划线参数释义 shell 编程 - shell 脚本的交互方式 Python insall - macOS 系统安装python的几种方式 Miniconda - Python 环境管理工具 Tkinter - Python GUI 开发 Python 编程 - 下划线命名的区别 Python 编程 - 元类编程 Python 编程 - 多重继承与MRO Python 编程 - 描述符协议 Python 编程 - 类型注解 Python 编程 - 生成器表达式 Python 编程 - 集合 Python 编程 - 装饰器 Python 编程 - 闭包 Python 编程 - 列表推导式 Python 编程 - 函数式编程 Python 编程 - lambda 函数 Python 编程 - 文件操作 Python 编程 - 输入与输出 Python 编程 - 面向对象编程 Python 编程 - 元组(tuple) Python 编程 - 字符串(str) Python 编程 - 字典(dict) Python 编程 - 列表(list) Python 编程 - 数据类型和数据结构 Python 编程 - 语句 Python 编程 - 函数 windows - WSL 的安装与使用 shell编程 - dialog 程序使用指南 FE Team - 如何做好前端代码审查 git 提交的撤销和恢复 React15 - redux-saga 如何在saga中实现轮询接口调用? React15 - React CSS Modules BEM命名实践 React15 - React 15 中 componentWillReceiveProps 为什么会多次调用, 同时componentDidUpdate 也会多次调用? React15 - React15类组件多次执行render方法的原因? React15 - React15应用中代码逻辑复用方案 React15 - React状态同步问题解决 React15 - React 15 中 React.pureComponent 的使用场景 React15 - React 15应用在页面渲染时会多次执行类组件的render 函数的原因 React15 - React 15 中能用 componetDidUpdate 代替 componentWillReceiveProps 吗? React15 - React 15 生命周期函数详解 React15 - 如何在React 15中实现自定义的事件订阅与发送(例如组件间通信) React15 - React15应用中的事件订阅和发送机制 React15 - CSS中的BEM规范 React15 - React CSS Modules BEM命名实践 React15 - 写sass 样式文件,嵌套的结构好,还是扁平的结构好? React15 - sass 中 @mixin 和 @extend 的区别是什么? React15 - React 15 应用 如何使用Css moudules 方式进行模块化开发 React15 - React15应用Sass使用指南 React15 - React 15 应用如何进行性能优化?
Tkinter - 几何管理器
箫笛 · 2026-07-10 · via 博客园 - 箫笛

几何管理器
控制控件的大小和位置

管理器 最佳适用场景 模型
pack 简单的线性布局 从上/下/左/右堆叠
grid 表单、表格 行/列网格
place 绝对定位 x/y 坐标或相对位置

⚠️ 不要在同一容器中混用管理器

不要对共享同一个父容器的控件同时使用 packgrid——这会导致无限几何循环并造成程序冻结。


pack()

widget.pack(side=TOP, fill=NONE, expand=False, anchor=CENTER, padx=0, pady=0)
选项 取值 说明
side TOP, BOTTOM, LEFT, RIGHT 沿着哪一侧堆叠
fill NONE, X, Y, BOTH 是否填充分配的空间
expand True / False 窗口变大时是否占据额外空间
anchor N, S, E, W, NE, NW, SE, SW, CENTER 有多余空间时的对齐方式
padx / pady int(int, int) 外部边距(像素)

sidebar_layout.py

container = ttk.Frame(root)
container.pack(fill=tk.BOTH, expand=True)

sidebar = ttk.Frame(container, width=120)
sidebar.pack(side=tk.LEFT, fill=tk.Y)

content = ttk.Frame(container)
content.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)

grid()

widget.grid(row=0, column=0, rowspan=1, columnspan=1, sticky="", padx=0, pady=0)

💡 columnconfigure / rowconfigure

当窗口调整大小时,始终对需要拉伸的列调用 parent.columnconfigure(n, weight=1)

grid_form.py

root.columnconfigure(1, weight=1)

ttk.Label(root, text="用户名:").grid(row=0, column=0, sticky="e", padx=8, pady=6)
ttk.Entry(root).grid            (row=0, column=1, sticky="ew", padx=8)

ttk.Label(root, text="密码:").grid(row=1, column=0, sticky="e", padx=8, pady=6)
ttk.Entry(root, show="*").grid     (row=1, column=1, sticky="ew", padx=8)

ttk.Button(root, text="登录").grid(row=2, column=0, columnspan=2, pady=12)

place()

widget.place(x=0, y=0, relx=0.0, rely=0.0, width=None, relwidth=None, anchor=NW)

place_center.py

# 使用相对坐标将控件居中
label.place(relx=0.5, rely=0.5, anchor=tk.CENTER)

布局配方

应用骨架(工具栏 + 内容区 + 状态栏)

app_skeleton.py

toolbar   = ttk.Frame(root, relief="raised")
toolbar.pack(side="top", fill="x")
content   = ttk.Frame(root)
content.pack(fill="both", expand=True)
statusbar = ttk.Label(root, text="就绪", relief="sunken")
statusbar.pack(side="bottom", fill="x")