Ballew
Ballew

Reputation: 288

How to exit a Kivy application using a button

I'm just learning Python and the Kivy framework. I can't seem to find any specific complete examples of being able to gracefully exit a Kivy app using code linked to a button.

I have found Kivy code snippets like this

Button:
    id:btnExit
    text:"Exit"
    on_press: app.Exit()

But not any matching code that implements the app.Exit() call. Everything I've tried stops code execution but doesn't clean up the program window.

I've read that Android and iOS style guides state that a program is not to programmatically exit and let the OS handle it but I am developing fullscreen borderless Desktop app and need a way to exit the program with a button press.

Upvotes: 22

Views: 45317

Answers (4)

Udit Hari Vashisht
Udit Hari Vashisht

Reputation: 549

I used

on_press : app.stop()

in Button's property in Kivy Layout File and it worked well for me.

Upvotes: 2

Sunil_Gupta
Sunil_Gupta

Reputation: 100

Try using self.root_window.close(). There is bug in new android toolchain.

Upvotes: 3

M.A.K. Ripon
M.A.K. Ripon

Reputation: 2148

Try using App.get_running_app().stop().
For more details, read the Kivy documentation article for the function.

Upvotes: 23

Ruben G
Ruben G

Reputation: 371

Use App.stop(*largs):

Button:
    id: btnExit
    text: "Exit"
    on_press: app.stop() 

Upvotes: 27

Related Questions