“为”的可能性循环 self.ids kivy python
我试图循环 API 以返回多个飞机位置坐标,但当我只运行 1 个坐标结果时。
我的问题是如何配置它才能执行 for 循环并显示飞机的所有位置?
main.py
class ExpertServer(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
data = get_json()
for i in data:
self.ids.markerview.lat = i['latitude']
self.ids.markerview.lon = i['longitude']
self.ids.markerview.angle = i['heading']
class MyApp(MDApp):
def build(self):
Builder.load_file('main.kv')
self.sm = ScreenManager()
self.sm.add_widget(Menu(name='menu'))
self.sm.add_widget(ExpertServer(name='expert'))
return self.sm
MyApp().run()
main.kv
#:import MapView kivy_garden.mapview.MapView
<ExpertServer>:
name: 'expert'
FloatLayout:
MapView:
zoom: 3
lat: 0
lon: 0
double_tap_zoom: True
MapMarkerPopup:
id: markerview
lat: 0
lon: 0
angle: 180
source: "map_marker.png"
canvas.before:
PushMatrix
Rotate:
angle: self.angle
origin: self.center
canvas.after:
PopMatrix
结果:
I'm trying to loop for an API to return multiple aircraft position coordinates, but when I run only 1 coordinate result.
my question is how can i configure it to be able to do a for loop and show all the positions of the aircraft?
main.py
class ExpertServer(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
data = get_json()
for i in data:
self.ids.markerview.lat = i['latitude']
self.ids.markerview.lon = i['longitude']
self.ids.markerview.angle = i['heading']
class MyApp(MDApp):
def build(self):
Builder.load_file('main.kv')
self.sm = ScreenManager()
self.sm.add_widget(Menu(name='menu'))
self.sm.add_widget(ExpertServer(name='expert'))
return self.sm
MyApp().run()
main.kv
#:import MapView kivy_garden.mapview.MapView
<ExpertServer>:
name: 'expert'
FloatLayout:
MapView:
zoom: 3
lat: 0
lon: 0
double_tap_zoom: True
MapMarkerPopup:
id: markerview
lat: 0
lon: 0
angle: 180
source: "map_marker.png"
canvas.before:
PushMatrix
Rotate:
angle: self.angle
origin: self.center
canvas.after:
PopMatrix
result:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论