Kivy/Kivymd 地图切换界面

Kivy/ Kivymd Map switch screens

我想单击一个将我重定向到地图的按钮。然后,当我单击地图 window 上的按钮时,我想回到开头 window https://i.stack.imgur.com/sxAr2.png

https://github.com/Mapquestions/map代码在这里

虽然我找不到任何文档来支持这一点,但我相信你不能在包含的 kv 文件中定义你的根小部件(至少我没能让它工作)。

因此,您的 main.kv 应该如下所示:

#:include binsmapview.kv

ScreenManager:
    Screen1:
    Screen2:

那么,你的binsmapview.kv可以是:

#:import MapView kivy.garden.mapview.MapView
#ScreenManager:  # does not work in included file
#    Screen1:
#    Screen2:

<Screen1>:
    name: 's1'  # corrected location of this line
    BinsMapView:
        lat: app.latitude
        lon: app.longitude
        zoom: 8
        on_zoom:
            self.zoom = 8 if self.zoom < 8 else self.zoom
        on_lat:
            self.start_getting_bins_in_fov()
        on_lon:
            self.start_getting_bins_in_fov()


        MDRaisedButton:

            text: "find closest bin"
            pos: root.width * 0.39, root.height * 0.1
            size: root.width * 0.25, root.height * 0.07
            md_bg_color: 102/255, 153/255, 255/255, 1
            halign: 'center'
            on_release: app.r()
<Screen2>:
    name: 's2'
    MDFloatLayout:

        MDRaisedButton:
            text: "go to next page"
            pos: root.width * 0.39, root.height * 0.1
            size: root.width * 0.25, root.height * 0.07
            md_bg_color: 102/255, 153/255, 255/255, 1
            halign: 'center'
            on_release: root.manager.current='s1'  # added this to switch screens back