我如何访问kivy中的全局变量

How can i access a global variable in kivy

我需要用 python 中的全局变量更新 kivy 中的标签。我该怎么做

我需要的最终结果是根据switch中断更新canvas的pos

.py

global x1

def hi():
    print "hi"
    x1 = 20
    print x1
class Mode1(Screen):
    global x1
    x1 = NumericProperty()
    y1 = NumericProperty()
    Buttonstatus = ''
    ButtonPressed=''

    def on_touch_move(self, touch):
        print 'x1'
        global x1
        print x1
        hi()

.KV

canvas.after:
    Color:
        rgb:[1, 0, 0,1]
    Rectangle:
        pos:root.x1,root.y1
        size:20,20

您已经在 class 中将 x1 声明为全局变量。在你的方法中尝试打印 self.x1。” 打印 self.x1