如何使用to_widget()在ScatterPlane中保持一些静止的东西

时间:2015-12-07 23:58:49

标签: python kivy

如果我想将某些元素保持在相对于窗口的ScatterPlane静止的位置,那么在kv中,我可以这样做:

ScatterPlane:
    Label:
        text: 'Locked to Window'
        pos: -root.x, -root.y

但是,如果我尝试:

pos: root.to_widget(0, 0)

它不起作用。这是为什么?

这里有一些代码可以证明这一点:

import kivy
kivy.require('1.9.0') 
from kivy.app import App 
from kivy.uix.label import Label 
from kivy.uix.scatter import ScatterPlane 
from kivy.uix.relativelayout import RelativeLayout 
from kivy.lang import Builder 

presentation = Builder.load_string(""" 
<ScatterPlane>: 
    Label: 
        #pos: root.to_widget(0, 0) #doesnt work 
        pos: -root.x, -root.y      #works 
        width: root.width 
        text: 'Test: ' + str(root.pos) + ', ' + str(root.to_widget(0, 0))  

RelativeLayout: 
    ScatterPlane: 
""") 


class TestApp(App): 
    def build(self): 
        return presentation  

if __name__ == '__main__': 
    TestApp().run()

0 个答案:

没有答案