我目前有这段代码,如果按下 ToggleButton 我想让它说
ToggleButton was pressed
然后说明 ToggleButton 是打开还是关闭(默认情况下它是打开的,如果按下按钮,它将被关闭)我想通过状态为 True 或 False 来执行此操作,但我不知道该怎么做这。任何帮助,将不胜感激
class Button(object):
def __init__(self, text = "button"):
self.label = text
def press(self):
print("{0} was pressed".format(self.label))
class ToggleButton(Button):
def __init__(self, text="ToggleButton", state=True):
self.label = text
例如我想要
b = ToggleButton()
b.press()
返回:
ToggleButton was pressed
ToggleButton is now OFF
谢谢!