私はコードを持っています
class Button(object):
'''A simple Button class to represent a UI Button element'''
def __init__(self, text = "button"):
'''Create a Button and assign it a label'''
self.label = text
def press(self):
'''Simply print that the button was pressed'''
print("{0} was pressed".format(self.label))
class ToggleButton(Button):
def __init__(self, text, state=True):
super(ToggleButton, self).__init__(text)
self.state = state
def press(self):
super(ToggleButton, self).press()
self.state = not self.state
print('{0} is now'.format(self.label), 'ON' if self.state else 'OFF')
入力すると
tb = ToggleButton("Test", False)
tb.press()
tb.press()
それは正常に動作し、戻ります
Test was pressed
Test is now ON
Test was pressed
Test is now OFF
しかし、私が望むのは、テキストパラメータをオプションにすることです。
b = ToggleButton()
b.press()
それは戻ってきます
ToggleButton was pressed
ToggleButton is now OFF
どんな助けでも大歓迎です!