Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is certainly possible. Here's a short example app with the method I use to do this:</p> <pre><code>from kivy.utils import platform from kivy.core.window import Window class ExampleApp(App): manager = ObjectProperty() def build(self): sm = MyScreenManager() self.manager = sm self.bind(on_start=self.post_build_init) return sm def post_build_init(self, *args): if platform() == 'android': import android android.map_key(android.KEYCODE_BACK, 1001) win = Window win.bind(on_keyboard=self.my_key_handler) def my_key_handler(self, window, keycode1, keycode2, text, modifiers): if keycode1 in [27, 1001]: self.manager.go_back() return True return False </code></pre> <p>This should give the right basic idea, but a few notes:</p> <ul> <li>ScreenManager doesn't keep track of the previous screens, it's up to you to implement this how you like. My example assumes you defined a class MyScreenManager with a go_back method.</li> <li>It might not be necessary to bind to on_start and run post_build_init, this is just how the example I originally used did it (see below). It might be important sometimes though, possibly if the window is not initialised when <code>build()</code> is run, and the original mailing list post suggests the author needed it for some reason.</li> <li>The example listens for keycodes 27 or 1001. As qua-non said while I was writing this, the former listens for <code>esc</code>, so you can get the same behaviour on desktop.</li> <li>I didn't try without the <code>android.map_key</code> line, but it seems like it may not be necessary.</li> <li>You mention you want to use kivy language and not python. You need to do some python to get this result, and I don't see a way around that (it's not really the domain of the kv language). I guess you could shift some stuff to kv by defining a 'go_back' event somewhere and triggering this when the key is pressed, along with binding your screenmanager to watch that event, but it seems like a long way around.</li> </ul> <p>I based my code on the mailing list thread at <a href="https://groups.google.com/forum/#!topic/kivy-users/7rOZGMMIFXI" rel="noreferrer">https://groups.google.com/forum/#!topic/kivy-users/7rOZGMMIFXI</a> . There might be a better way, but this is quite functional.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload