0

my kivy simple hello world app is not closing I'm using raspberry pi B and I can't close it I must unplug my raspberry pi 5v adapter to close it

I'm using rasbian jessie this is the very simple code

import kivy
from kivy.app import App
from kivy.uix.label import Label

class mamdouh(App):
    def build(self):
        return Label(text='mamdouh')

if __name__=='__main__':
    mamdouh().run()
Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
mamdouh abdelfatah
  • 43
  • 1
  • 3
  • 10
  • I think the idea is that you should have some ui element that when clicked will call the `stop` method of your application object. What you could do is assign your app to an actual variable e.g. `app = mamdouh()` then `app.run()`. Then add a `Button`, which will be assigned a function when clicked. In that function call `app.close()` and ti will quit. – Paul Rooney May 03 '16 at 05:14

1 Answers1

0

What I was trying to say in the comment was. That you need to have some action to cause the quit, as the run method will run in a loop indefinitely otherwise.

If you now click on the Button labeled 'paul' it will quit.

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button


class mamdouh(App):

    def build(self):
        lbl = Label(text='paul')
        btn = Button(text='mamdouh')
        btn.bind(on_press=lambda b: app.stop())

        lbl.add_widget(btn)

        return lbl

if __name__ == '__main__':

    app = mamdouh()
    app.run()

I know nothing about kivy but I can see that this should allow you to quit, whether you want a Button in your app is another question.

Another way to kill it and avoid the reboot is simply to go back to the prompt where you launched your app and do CTRL + C. This will only work from the prompt though, not from the app window itself.

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61