1 回答

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊
試試這個(gè):
class MyTextInput(TextInput):
def __init__(self, **kwargs):
super(MyTextInput, self).__init__(**kwargs)
self.input_filter = 'int'
def insert_text(self, substring, from_undo=False):
if substring in string.digits:
cc, cr = self.cursor
text = self._lines[cr]
new_text = text[:cc] + substring + text[cc:]
if int(new_text) > 100:
return
super(MyTextInput, self).insert_text(substring, from_undo=from_undo)
添加回答
舉報(bào)