首页 > 解决方案 > 在与 kivy python 相同的窗口中添加 MapView 和按钮、标签等

问题描述

我从来没有使用过 OOP 和 Kivy,所以我在这里问你。我想在同一个屏幕中插入地图和按钮、标签等,但我真的不知道如何,你有任何教程或任何东西?

我当前的代码:

主要.py:

import kivy
from kivy.app import App
from kivy_garden.mapview import MapView
from kivy.uix.floatlayout import FloatLayout


class MyApp(App):
    def build(self):
        return FloatLayout()



if __name__ == "__main__":
    MyApp().run()

我的.kv:

#:import MapView kivy.garden.mapview.MapView

MapView:

    size_hint: 0.6,0.7
    pos_hint: {"x":0.4, "top":0.8}
    lat: 46.691858
    lon: 3.048459
    zoom: 6
    on_lat:
        print("latitude : ",self.lat)
    on_lon:
        print("longitude : ",self.lon)

    MapMarkerPopup:
        lat:46
        lon:3

        
<Button>:
    font_size: 24
    color:0.5,0.2,0.3,1
    size_hint: 0.1,0.05

<FloatLayout>:
    Button:
        pos_hint: {"x":0.02, "top":1}
        text: "OK"

    Button:
        id: btn
        text: "OK 2" if btn.state == "normal" else "Appui"
        pos_hint: {"x":0.02, "top":0.9}

我认为这真的很简单,但目前我不知道该怎么做..

谢谢 !

PS:我为 windows 10、7 和 xp 开发此应用程序,而不是为 android

标签: pythonkivymkmapview

解决方案


推荐阅读