-2

I got a little beginner question about Classes and the self. My Function checkAbonnement looks like that right now:

    def checkAbonnement(self):
    # Create Labels and Buttons
       self.text = Label(text="Choose the Subscription you got")
       self.text.grid(row=1, column=0)
       self.aboButton = Button(window, text="No Subscription", command=lambda:[self.setAbonnement(1), self.checkGutschein()])
       self.aboButton.grid(row=2, column=0)
       self.aboButton_2 = Button(window, text="Silver Subscription", command=lambda:[self.setAbonnement(2), self.checkGutschein()])
       self.aboButton_2.grid(row=3, column=0)
       self.aboButton_3 = Button(window, text="Gold Subscription", command=lambda:[self.setAbonnement(3), self.checkGutschein()])
       self.aboButton_3.grid(row=4, column=0)
       self.aboButton_4 = Button(window, text="Platinum Subscription", command=lambda:[self.setAbonnement(4), self.checkGutschein()])
       self.aboButton_4.grid(row=5, column=0)

Like you can see, there are a bunch of self. in there...

My question is now: Are they needed or is there a better option to declare them to my Class other than using self.

class ScooTeq:
Marius1773
  • 23
  • 5
  • `self` itself isn't really important. The thing to understand is *why* your method has a parameter (conventionally called `self` but you can use any name you like) which doesn't appear to take an argument when you call the method. – chepner Jun 14 '21 at 20:38

1 Answers1

0

If you want these attributes to be unique across instances of ScooTeq, then you have to use self. I agree it can be tedious, but it is to avoid ambiguity. There is more information on this here.

Adin Ackerman
  • 202
  • 1
  • 7