python - Tkinter Button 类中的文本参数在哪里?

标签 python button tkinter

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/

相关文章:

python - pytest 不会运行子目录中的测试文件

python - 替换满足特定阈值的python ndarray的值

python - 列出重复的并集

python - 统一码解密

ruby-on-rails - 禁用提交按钮,除非 file_field_tag 在 Ruby on Rails 中不为 null

WPF——它比我做的要容易

Android:以编程方式更改语言

python tkinter接口(interface)如何创建一个新的显示txt文件

python - 使用 Tkinter 和 Python 将同一框架内的两个不同类插入笔记本时仍然存在问题

python - 获取目录后更新文件路径