I am trying to use multiple buttons that all call the same function but have different parameters of 1, 2, 3, and so on. I want to have these parameters pass through the function in the class and only affect the object whose name matches that parameter. My issue is that I do not know how to use parameters with objects using self. I am new to programming and tkinter so any help, tips, or criticism is appreciated. If I messed up anything in my explanation please also let me know, thanks.
class Main(tk.Tk):
def __init__(self):
super().__init__()
self.sub_app1= None
self.sub_app2= None
self.sub_app3= None
b1 = tk.Button(self, text="Open Sub App One", command= lambda: self.sub_app_open(1))
b1.pack(padx=20, pady=20)
def sub_app_open(self, app):
#self.sub_app = ("sub_app" + str(app))
if self.sub_app(1) is None:
print(type(self.sub_app1))
self.sub_app = window1(self)
I will add more buttons calling that same function with a parameter that correlated to self.sub_app1, 2, and 3. I already tried doing sub_app + str(app) but my little knowledge of types let me down.
sub_app1
,sub_app2
, etc. Make it a list or dictionary, and pass the index or key as theapp
parameter.getattr(self, f"sub_app{app}")