Kivy Plyer 通知

3

我对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()
1个回答

3

notify()Notification类的一个方法,并且没有被标记为@staticmethod。因此,您需要该类的实例才能调用它。

根据文档,创建通知的正确方式如下:
from plyer import notification
notification.notify(title='hehe', message='huhu')

很好,我不知道为什么我没想到。谢谢! - Dyzlee
@Dyzlee 很高兴我能帮到你 :-) - O.O.Balance

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接