简体   繁体   中英

How can i access a global variable in kivy

I need to update a label in kivy with a global variable in python. How can I do that

The final result I need is to update the pos of canvas according to the switch interrupt.

.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

You already declared x1 as a global variable in your class. In your method try printing self.x1." print self.x1"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM