我试图增加变量值,但出现以下错误:
"UnboundLocalError: local variable 'x' referenced before assignment"
有人能帮我吗
.kv:
<InputValuesScr>:
GridLayout:
rows:2
TextInput:
input_filter: 'float'
font_size: 50
text: 'Please, input value of x1'
id: xval
multiline: False
on_touch_down: self.text = ''
Button:
text: 'Submit'
on_press: root.x_changer()
.py:
global x
x = 1
class TypeOfGeometryScr(Screen):
pass
class SelectDemensionsScr(Screen):
def submit_dn(self):
global dn
dn = self.ids.demensions.text
class InputValuesScr(Screen):
def x_changer(self):
x = x
x += 1
self.ids.xval.text = 'Please, input value of x' + str(x)
发生这种情况是因为
global x
在全局范围内,而不是在x_changer()
函数lac范围内。为了解决这个问题,你需要在函数的局部范围内移动global x
相关问题 更多 >
编程相关推荐