tkinter 中的父/母与 in_ [英] Parent/master vs. in_ in tkinter

查看:35
本文介绍了tkinter 中的父/母与 in_的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查以下代码:

import Tkinter as tk

root=tk.Tk()
f1 = tk.Frame(width=200, height=200, background="red")
f2 = tk.Frame(width=100, height=100, background="blue")

f1.pack(fill="both", expand=True, padx=20, pady=20)
f2.place(in_=f1, anchor="c", relx=.5, rely=.5)

root.mainloop()

取自:我如何居中Tkinter 框架内的框架?

那里的评论之一说当小部件未明确指定父窗口时,根窗口是默认值"" 在这种情况下,f1 由根管理window 和 f2 由 f1 管理(因为 in_ 参数)."

One of the comments there says "The root window is the default when a widget doesn't explicitly specify a parent" and also " In this case f1 is being managed by the root window and f2 is being managed by f1 (because of the in_ parameter)."

由用于实例化新小部件的主参数创建的层次结构与由 .place 布局管理器中使用的 in_ 参数创建的层次结构有何区别?

What is the difference between the hierarchy created by the master parameter used in the instantiation of new widgets and the hierarchy created by the the in_ prameter used in the .place layout manager?

为什么 f2 没有被创建为 f1 的子级?(它会改变什么吗?)

Why is f2 not being created as a child of f1? (and would it change anything?)

推荐答案

我缺乏理解似乎是我的代码中的一个问题的结果,我在这里得到了答案:tkinter 小部件的放置

My lack of understanding seems to have been the result of a problem in my code for which I got an answer here: tkinter placement of widgets

摆脱那里描述的问题,我现在可以看到:

Getting rid of the issue describe there I can now see that:

主/父:定义一个边界区域,限制其子小部件的渲染

Master/parent: defines a bounding area limiting the rendering of its child widgets

in_:设置 in_(included) 小部件的 定位 所基于的小部件

in_: sets the widget on which the positioning of the in_(cluded) widget would be based

这篇关于tkinter 中的父/母与 in_的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆