如果我想让某些元素相对于窗口保持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()
目前没有回答
相关问题 更多 >
编程相关推荐