Python 如何将TKinter中的.configure压缩为一个命令?

Python 如何将TKinter中的.configure压缩为一个命令?,python,tkinter,Python,Tkinter,我正在创建一个程序,将使用多个菜单和按钮,并使菜单快速(由于我不是很精通Tkinter),我已经使用页面生成一些代码为我。然而,它为每个按钮输出了一组非常长的.configure语句,这意味着我的项目现在总共有1400多行代码——我甚至还没有完成一半。是否有一种方法可以将所有这些。配置命令转换为一个?我在下面提供了我的代码示例以供参考 self.Button7 = Button(top) self.Button7.place(relx=0.04, rely=0.76, height=24, wi

我正在创建一个程序,将使用多个菜单和按钮,并使菜单快速(由于我不是很精通Tkinter),我已经使用页面生成一些代码为我。然而,它为每个按钮输出了一组非常长的.configure语句,这意味着我的项目现在总共有1400多行代码——我甚至还没有完成一半。是否有一种方法可以将所有这些。配置命令转换为一个?我在下面提供了我的代码示例以供参考

self.Button7 = Button(top)
self.Button7.place(relx=0.04, rely=0.76, height=24, width=257)
self.Button7.configure(activebackground="#d9d9d9")
self.Button7.configure(activeforeground="#000000")
self.Button7.configure(background="#d9d9d9")
self.Button7.configure(command=root.destroy)
self.Button7.configure(disabledforeground="#a3a3a3")
self.Button7.configure(foreground="#000000")
self.Button7.configure(highlightbackground="#d9d9d9")
self.Button7.configure(highlightcolor="black")
self.Button7.configure(pady="0")
self.Button7.configure(text='''Go back''')

您可以将它们全部放在一个命令中:

self.Button7.configure(foreground="#000000", highlightbackground="#d9d9d9", highlightcolor="black", etc)

但你为什么要这么做?按你的方式做要整洁得多

您可以为配置需要传递的参数创建一个
字典
,然后使用
**
,如下所示

my_config = {
    'foreground': "#000000",
    'background': "#d9d9d9",
    # ...
}
self.Button7.configure(**my_config)

您甚至不需要使用
.configure()
——相同的关键字直接在
按钮()
构造函数中工作。“页面”是什么?