因此,我试图使用其他类中的方法,但是我必须使用from中的方法添加类中的所有参数。反正还有吗?
class MainPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text = "aaaa")
label.pack(pady = 10, padx = 10)
A = managers()
method = getattr(A, printAll) ## "printAll" is the method im trying to get
addemployee = tk.Button(self, text = "Start", command = method)
addemployee.pack(pady = 10, padx = 10)
class managers(workers):
def __init__(self, firstname, surname, age, postcode, wage, Employees = None):
super().__init__(firstname, surname, age, postcode, wage)
def printAll(self): #### the method i want to use
for emp in self.employees:
print(emp.Fullname(), "-", emp.Age(), "-", self.Postcode(), "-", self.Wage())
答案 0 :(得分:0)
您可以使用默认值,因此不必传递所有内容。
class managers(workers):
def __init__(self, firstname="fname", surname="sname", age="196", postcode="pc", wage="1$", Employees = None):
this SO answer中建议的另一种允许您完全自由的选项是使用args和关键字args def __init__(self, *args, **kwargs):