【问题标题】:Kivy Plyer NotificationKivy Plyer 通知
【发布时间】:2019-12-31 22:53:00
【问题描述】:

我对 kivy 很陌生,我刚刚尝试了 Plyer 来制作我正在制作的应用程序。但由于某种原因,我无法让 notify 方法工作,并且一旦 Clock 方法运行,它就会给我这个错误:TypeError: notify() missing 1 required positional argument: 'self'

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.switch import Switch
from kivy.clock import Clock
from kivy.uix.label import Label
import datetime
from kivy.event import EventDispatcher
import plyer

count = 0


class ConnectPage(GridLayout):
    def __init__(self, **kwargs):
        super(ConnectPage, self).__init__(**kwargs)
        self.cols = 1
        self.switch = Switch()
        self.add_widget(self.switch)

        self.label = Label(text="0")
        self.add_widget(self.label)

    def manager(self):
        global count
        count += 1
        print("[", count, "]")
        plyer.facades.Notification.notify(title='hehe', message='huhu')

    Clock.schedule_interval(manager, 1 / 1.)


class TestService(App):
    def build(self):
        return ConnectPage()


TestService().run()

【问题讨论】:

    标签: python android notifications kivy


    【解决方案1】:

    notify()Notification类的一个方法,它没有被标记为@staticmethod。所以你需要一个类的实例来调用它。 根据documentation,创建通知的正确方法是:

    from plyer import notification
    notification.notify(title='hehe', message='huhu')
    

    【讨论】:

    • 这很好,我不知道为什么我没有想到它。谢谢!
    • @Dyzlee 很高兴我能帮上忙 :-)
    猜你喜欢
    • 2016-06-11
    • 2021-11-10
    • 2016-08-23
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    • 1970-01-01
    • 2015-10-23
    相关资源
    最近更新 更多