gpt4 book ai didi

python - Kivy Plyer通知

转载 作者:行者123 更新时间:2023-11-29 22:53:23 26 4
gpt4 key购买 nike

我是 kivy 的新手,我刚刚为我正在制作的应用程序尝试了 Plyer。但由于某种原因,我无法让通知方法工作,并且一旦 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()

最佳答案

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

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

关于python - Kivy Plyer通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57680073/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com