python - 与按钮不同的列中的 Tkinter 包装条目
问题描述
我正在使用一个简单的代码:
frame_bottom = Frame(root)
frame_bottom.pack(fill='x')
button1 = Button(frame_bottom, text = 'One', command = visualize)
button2 = Button(frame_bottom, text = 'Two', state = DISABLED)
label_rango1 = Label(frame_bottom, text = 'Sigma value:')
e_sigma = Entry(root, borderwidth = 2)
label_rango1.pack(side='left', expand=True)
e_sigma.pack(side='left')
button1.pack(side='left', expand=True)
button2.pack(side='left', expand=True)
然而,尽管使用side='left'
,该条目仍位于其余按钮下方。关于如何将所有内容打包在同一行中的任何想法?
谢谢!
解决方案
原因是因为button1
andbutton2
是 的孩子frame_bottom
,但是e_sigma
是 的孩子root
。frame_bottom
您之前打包e_sigma
并且不提供任何选项,因此frame_bottom
被添加到根窗口的顶部(好吧,可用空间的顶部,如果您已经在根窗口中打包了其他小部件,这很重要)。当你打包e_sigma
时,它必须放在下面定义的剩余空间中frame_bottom
。
换句话说,frame_bottom
并且e_sigma
都是 的孩子root
。frame_bottom
首先打包,然后e_sigma
打包,都带有默认选项。因此,frame_bottom
会出现在上面e_sigma
。
如果您希望条目位于按钮的右侧,则它需要与按钮具有相同的父级。
推荐阅读
- linux - NixOps:如何部署到现有的 NixOS VM?
- python - Python合并不相等的数据框
- python - 使用 /insights edge 的 Instagram Graph API 问题
- spring - 具有由多个线程调用的方法的 Spring 组件
- python - django select_related() 和 django-mptt。如何一次获取所有兄弟姐妹?
- python - 将列格式代码应用于多个数据框
- sql - 如何加入 2 个表并仅保留最新记录
- python - Keras 的损失一度陷入 CNN
- python - 将参数传递给python中的深层嵌套函数
- php - 路由中的可选参数取决于参数位置