【发布时间】:2021-06-13 22:34:19
【问题描述】:
我想制作一个 Button,它以紧凑的形式为新变量分配一个值。
我试过了:
def whichButton(self, _var, _pressedButton):
self._var = _pressedButton
def checkScooter(self):
self.checkScooter = Button(window, text="Standard", command=lambda: self.whichButton(edition, 1))
self.checkScooter(row=1, column=0)
def checkAbonnement(self):
self.checkAbonnement = Button(window, text="Gold", command=lambda: self.whichButton(abonnement, 3))
self.checkAbonnement(row=1, column=0)
它只是给我一个错误,没有定义“版本”,但我希望按钮来定义它
有什么建议吗?
【问题讨论】:
-
这样做不是一个好习惯。为什么不将其拆分为 2 个功能?
-
我编辑的,你是这个意思吗?
-
我的意思是拆分它,以便 2 个按钮调用 2 个不同的功能。如果您这样做,这些功能将是微不足道的。
-
不会溢出程序吗?如果你每次都做一个新功能?编辑:我只需要为我的程序做 2 个功能,但如果你有多个?
-
它将使其更具可读性。如果您的程序不可读,则以后无法对其进行调试。如果你真的想按照自己的方式做,我可以写一个答案,但它真的很难看,如果出现错误,......
标签: python tkinter tkinter-button