RandomPesho
RandomPesho

Reputation: 7

Kivy/ Kivymd Map switch screens

I want to click a button which directs me to the map. Then when I click a button on the window of the map I want to go back to the beginning window https://i.sstatic.net/sxAr2.png

https://github.com/Mapquestions/map code is here

Upvotes: 0

Views: 326

Answers (1)

John Anderson
John Anderson

Reputation: 39092

Although I cannot find any documentation to support this, I believe that you cannot define your root widget in an included kv file (at least I have not been able to get that to work).

So, your main.kv should look like this:

#:include binsmapview.kv

ScreenManager:
    Screen1:
    Screen2:

Then, your binsmapview.kv can be:

#: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

Upvotes: 0

Related Questions