我正在尝试以这种方式更新我的标签,我有一个标签和一个功能,当我使用此功能时,我的标签会在其文本中添加一个数字。这样,如果我的标签在我点击按钮之前是1,那么在我点击一个按钮之后,标签就会变成1+x。我不知道我该怎么做。是纯代数。
.py
class PrimeiroScreen(Screen):
def __init__(self,**kwargs):
self.name = 'uno'
super(Screen,self).__init__(**kwargs)
def fc(self):
self.ids.lb1.text += "1" #its add 1 in the label, but not sum 1 to label value
和.kv
<PrimeiroScreen>:
GridLayout:
cols: 1
size_hint: (.3, .1)
pos_hint:{'x': .045, 'y': .89}
Label:
text:"0"
font_size: '30dp'
text_size: self.width, self.height
id: lb1
Button:
text: "Somar 3"
font_size: '30dp'
text_size: self.width - 50, self.height
on_press: root.fc()