0

So im trying to use a method from another class but im having to add all the paramenters from the class im using the method from. is there anyway around this?

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())
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
manlike
  • 45
  • 1
  • 11
  • How will you use that method if you don't instantiate those attributes? – cs95 Jul 15 '18 at 19:23
  • Also, what does your MainPage class have to do with this question? – cs95 Jul 15 '18 at 19:24
  • @coldspeed i dont want to re-add the parameters as i have made an object with all the info at the botton of the class. `a = managers("Sha", "Jan", 21, "UB4 NM3", 1900000)`, as for the MainPage, it was just an example, i have not supplied all the code. Only the necessary parts. – manlike Jul 15 '18 at 19:27

1 Answers1

0

You can use default values so you don't have to pass everything.

class managers(workers):

def __init__(self, firstname="fname", surname="sname", age="196", postcode="pc", wage="1$", Employees = None):

The other option that allows you complete freedom, as suggested in this SO answer is to pass params using args and keyword args def __init__(self, *args, **kwargs):

itaintme
  • 1,575
  • 8
  • 22