【发布时间】:2021-08-30 18:00:09
【问题描述】:
我有一个关于 Classes 和 self. 的初学者小问题
我的函数 checkAbonnement 现在看起来像这样:
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)
如你所见,里面有一堆self....
我现在的问题是:除了使用 self. 之外,是否需要它们或者是否有更好的选择向我的班级声明它们
class ScooTeq:
【问题讨论】:
-
self本身并不重要。要理解的是为什么您的方法有一个参数(通常称为self,但您可以使用您喜欢的任何名称)在您调用该方法时似乎不带参数。跨度>
标签: python class tkinter declaration