python - tkinter 中的网格和打包顺序
问题描述
我从 Tkinter 开始,并尝试了解不同的几何包管理器。我发现了一些奇怪的东西,我想要一个解释。
我测试了两段代码:
import tkinter as tk
fen = tk.Tk()
fr1 = tk.Frame(fen).grid(row=0,column=0)
fr2 = tk.Frame(fen).grid(row=0,column=1)
txt1 = tk.Label(fr1, text="txt1").pack(side="top")
tk.Frame(fr1,bg="blue",height=5).pack(side="bottom",fill="x")
txt2 = tk.Label(fr2, text="txt2").pack(side="top")
tk.Frame(fr2,bg="red",height=5).pack(side="bottom",fill="x")
和
import tkinter as tk
fen = tk.Tk()
fr1 = tk.Frame(fen)
fr2 = tk.Frame(fen)
txt1 = tk.Label(fr1, text="txt1").pack(side="top")
tk.Frame(fr1,bg="blue",height=5).pack(side="bottom",fill="x")
txt2 = tk.Label(fr2, text="txt2").pack(side="top")
tk.Frame(fr2,bg="red",height=5).pack(side="bottom",fill="x")
fr1.grid(row=0,column=0)
fr2.grid(row=0,column=1)
只是调用网格的位置不同。
第一个给我一个几何错误:
“不能在里面使用几何管理器包。它已经有网格管理的奴隶”
第二个有效。
为什么会有这种行为差异?
解决方案
推荐阅读
- android - Flutter:如何将多张照片或图标内的一张照片链接到地理位置标记?
- flutter - MissingPluginException - shared_preferences、image_picker 等。在删除 flutter_branch_sdk 时有效
- struct - 为什么在结构定义中使用#transparent 的属性会降低 Racket 中的代码模块化?
- mysql - 为什么在尝试创建表时出现语法错误?
- excel - Excel,从匹配类别的表格中选择日期和金额
- android - Kotlin Android 应用程序的dimens.xml 是否也接受“sp”?
- mysql - AWS RDS MySQL 可疑延迟(同时 50 个用户的生产要求是什么)
- java - JOOQ - 获取不具有所有属性的自定义 POJO
- python - Python CSV(DictWriter)覆盖数据?
- python - Python 上的 Selenium 无法定位嵌套类元素