Python初学者在这里!
我正在学习 Tkinter,当我创建一个按钮时,他们使用了这个:
quitButton = Button(self, text="Quit")
我去检查 __init__ 脚本中 tkinter 模块下 Button 的声明,它显示:
class Button(Widget):
"""Button widget."""
......
......
所以我的问题是,为什么我们能够传递文本参数?
最佳答案
Button
类将其所有关键字参数 (**kw
) 转发到其基类 (Widget
)。您可以在此处查看它是如何做到的
class Button(Widget):
"""Button widget."""
def __init__(self, master=None, cnf={}, **kw):
"""Construct a button widget with the parent MASTER.
STANDARD OPTIONS
activebackground, activeforeground, anchor,
background, bitmap, borderwidth, cursor,
disabledforeground, font, foreground
highlightbackground, highlightcolor,
highlightthickness, image, justify,
padx, pady, relief, repeatdelay,
repeatinterval, takefocus, text,
textvariable, underline, wraplength
WIDGET-SPECIFIC OPTIONS
command, compound, default, height,
overrelief, state, width
"""
Widget.__init__(self, master, 'button', cnf, kw)
关于python - Tkinter Button 类中的文本参数在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50416562/