簡體   English   中英

如何在Kivy中訪問全局變量

[英]How can i access a global variable in kivy

我需要使用python中的全局變量來更新kivy中的標簽。 我怎樣才能做到這一點

我需要的最終結果是根據切換中斷來更新canvas的位置。

的.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

您已經在類中將x1聲明為全局變量。 在您的方法中嘗試打印self.x1。“ print self.x1”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM