python - 在 kivy 退出时做点什么

标签 python kivy

我正在 kivy 中制作一个应用程序,所以我想在退出 kivy 应用程序时做一些事情,以便运行该代码背景而不显示它

即使直接返回主页并在后台删除它也必须工作 like this image它必须工作,然后将所有 python 代码转换为 apk

# import kivy module     
import kivy   
       
# base Class of your App inherits from the App class.     
# app:always refers to the instance of your application    
from kivy.app import App  
     
# this restrict the kivy version i.e   
# below this kivy version you cannot   
# use the app or software   
kivy.require('1.9.0')  
     
# Importing Drop-down from the module to use in the program 
from kivy.uix.dropdown import DropDown 
  
# The Button is a Label with associated actions 
# that are triggered when the button is pressed 
# (or released after a click / touch) 
from kivy.uix.button import Button 
  
# another way used to run kivy app  
from kivy.base import runTouchApp 
  
# create a dropdown with 10 buttons 
dropdown = DropDown() 
for index in range(10): 
  
    # Adding button in drop down list 
    btn = Button(text ='Value % d' % index, size_hint_y = None, height = 40) 
  
    # binding the button to show the text when selected 
    btn.bind(on_release = lambda btn: dropdown.select(btn.text)) 
  
    # then add the button inside the dropdown 
    dropdown.add_widget(btn) 
  
# create a big main button 
mainbutton = Button(text ='Hello', size_hint =(None, None), pos =(350, 300)) 
  
# show the dropdown menu when the main button is released 
# note: all the bind() calls pass the instance of the caller  
# (here, the mainbutton instance) as the first argument of the callback 
# (here, dropdown.open.). 
mainbutton.bind(on_release = dropdown.open) 
  
# one last thing, listen for the selection in the  
# dropdown list and assign the data to the button text. 
dropdown.bind(on_select = lambda instance, x: setattr(mainbutton, 'text', x)) 
  
# runtouchApp: 
# If you pass only a widget in runtouchApp(), a Window will 
# be created and your widget will be added to the window 
# as the root widget. 
runTouchApp(mainbutton)

最佳答案

您可以使用Appon_stop 属性来做到这一点,如documented .当然,您需要创建一个 App使用它。

关于python - 在 kivy 退出时做点什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65304279/

相关文章:

列表性能中的Python模糊匹配字符串

python - 如何从 kivy/python 中的小部件树中获取所有小部件的列表。递归函数没有按预期工作

python - 基于列表在python numpy中排列数据的最快方法

python - 将 kivy 与 pywinauto 一起使用时出现 ctypes.ArgumentError

python-3.x - Kivy .kv 文件使用外部文件中定义的函数

Python/Kivy : conditional design in . kv 文件

来自《Kivy Blueprints》一书的 Python kivy 代码

python - Python什么时候创建一个新对象

python - string.format 中小数位数可变

python - CondaHTTPError : HTTP 000 CONNECTION FAILED for url - Anaconda