长话短说: Tkinter 中是否有一个函数可以获取小部件的主框架名称?
让我再告诉你一点:
有一个按钮,名为“后退按钮”
self.BackButton = Button(self.SCPIFrame, text = "Back", command = self.CloseFrame)
self.BackButton.place(x = 320, y = 320, anchor = CENTER)
当我单击此按钮时,有一个名为“CloseFrame”的函数,它关闭当前框架(并执行一些其他操作),在本例中为“SCPIFrame”。但为此,我需要其中存在 BackButton 的框架的名称。
有任何想法吗?谢谢你的帮助。
我认为最好的方法是使用 .master 属性,它实际上是 master 的实例:)
例如(我在 IPython 中这样做):
import Tkinter as tk
# We organize a 3-level widget hierarchy:
# root
# frame
# button
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
button = tk.Button(frame, text="Privet!", background='tan')
button.pack()
# Now, let's try to access all the ancestors
# of the "grandson" button:
button.master # Father of the button is the frame instance:
<Tkinter.Frame instance at 0x7f47e9c22128>
button.master.master # Grandfather of the button, root, is the frame's father:
<Tkinter.Tk instance at 0x7f47e9c0def0>
button.master.master.master # Empty result - the button has no great-grand-father ;)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)