pos_hint を使用してウィジェット (例: Scatter) を配置した後、現在の x、y 位置 (pos) を取得するにはどうすればよいですか?
例えば
wid.pos = (250, 350)
print wid.pos <----- # it print (200, 350). Correct.
wid.pos_hint = {'top':0.9, 'right':0.5} # moved the widget to other position using pos_hint.
print wid.pos <----- # it sill print (200, 350) eventhough the widget position has changed.
編集: コード例
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.scatter import Scatter
Builder.load_string("""
<Icon@Scatter>:
size_hint: .06, .08
Image:
size: root.size
allow_stretch: True
keep_ratio: True
""")
class Icon(Scatter):
def __init__(self, **kwargs):
self.pos = (200, 200)
self.move()
super(Icon, self).__init__(**kwargs)
def move(self):
print "BEFORE: "
print self.pos # print 200, 200
self.pos_hint = {'top':0.9, 'right':0.5} # assume now Scatter has moved to x800 y500.
print "AFTER: "
print self.pos # it still print 200, 200 :(
class GameApp(App):
def build(self):
return Icon()
if __name__ == '__main__':
GameApp().run()