Reputation:
I am creating a program which will use multiple menus and buttons, and to make the menus quick (and as I am not very proficient with Tkinter) I have used PAGE to generate some code for me. However, it outputs a very lengthy set of .configure statements for each button, meaning my project now totals over 1400 lines of code- and I'm not even halfway done yet. Is there a way I can turn all of these .configure commands into one? I have included a sample of my code below for reference.
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''')
Upvotes: 1
Views: 37
Reputation: 13373
You can create a dictionary
of the arguments that need to be passed for configuration and then use the argument unpacking magic **
, like below.
my_config = {
'foreground': "#000000",
'background': "#d9d9d9",
# ...
}
self.Button7.configure(**my_config)
Upvotes: 1
Reputation: 13729
You can put them all in a single command:
self.Button7.configure(foreground="#000000", highlightbackground="#d9d9d9", highlightcolor="black", etc)
But why would you want to? It's much neater to do it your way.
Upvotes: 1