I want to write a function to set an attribute of a class equal to an inputted value. The problem is that I don't want to know the name of the attribute.
The reason I want to do this is because I want to make a factory class for tkinter widgets that will take in the desired default settings. The factory class will have a method that instantiates a tkinter.Button with the default settings unless overridden upon calling the method.
I'd rather not hard code the settings if possible as I'd like to use this for multiple projects so having to make copies and edit them for each project isn't ideal.
This is the pseudocode for what I'm trying to do:
from tkinter import Button
class Factory:
def __init__(self, **kwargs):
for attr_name in list(kwargs.keys()):
self.attr_name=kwargs[attr_name]
def makeButtonWithText(self, text=None):
if text is None:
if self.text exists:
Button(TK(), text)
else:
Button(Tk())
else:
Button(Tk(), text)