Kivy Plyer通知

2024-04-26 20:41:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个非常新的基维和我刚刚尝试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()

Tags: 方法fromimportselfappdefcountnotify
1条回答
网友
1楼 · 发布于 2024-04-26 20:41:53

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

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

相关问题 更多 >