我写得不对吗?打开应用程序后,Android设备必须振动,但在应用程序打开后,它会崩溃。为什么我的kivy应用程序崩溃了?代码:
from plyer import vibrator
from kivy.app import App
from kivy.properties import StringProperty
from kivy.clock import Clock, mainthread
from kivy.uix.floatlayout import FloatLayout #the UI layout
from kivy.uix.label import Label #a label to show information
class UI(FloatLayout):
"""docstring for UI"""
def __init__(self):
super(UI, self).__init__()
self.lblAcce = Label(text="Vibrate: ") #create a label at the center
self.add_widget(self.lblAcce) #add the label at the screen
time = 2
try:
vibrator.vibrate(time=time)
#if you want do disable it, just run: accelerometer.disable()
Clock.schedule_interval(self.update, 1.0/24) #24 calls per second
except:
self.lblAcce.text = "Failed to start vibrate" #error
class Vibrate(App): #our app
def build(self):
ui = UI()# create the UI
return ui #show it
if __name__ == '__main__':
Vibrate().run() #start our app