简体   繁体   English

python:kivy应用无法关闭

[英]python: kivy app not closing

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 我的猕猴桃简单的hello world应用程序未关闭我正在使用raspberry pi B,但无法将其关闭,必须拔下raspberry pi 5v适配器以将其关闭

I'm using rasbian jessie this is the very simple code 我正在使用rasbian jessie,这是非常简单的代码

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()

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. 您需要采取一些措施来导致退出,否则run方法将无限期地循环运行。

If you now click on the Button labeled ' paul ' it will quit. 如果现在单击标有“ paul ”的Button ,它将退出。

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. 我对kivy一无所知,但我可以看到这应该允许您退出,是否要在应用程序中使用Button是另一个问题。

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 . 杀死它并避免重新启动的另一种方法是简单地返回到启动应用程序并执行CTRL + C的提示 This will only work from the prompt though, not from the app window itself. 但是,这仅在提示符下有效,而在应用程序窗口本身中无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM