python - Kivy Plyer 通知
问题描述
我对 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()
解决方案
notify()
是类的方法,Notification
没有标记@staticmethod
。所以你需要一个类的实例来调用它。根据文档,创建通知的正确方法是:
from plyer import notification
notification.notify(title='hehe', message='huhu')
推荐阅读
- rust - 将petgraph点写入文件
- javascript - 使用 Vue 和 webpack 钩住 HMR
- python - 使用python在硒中打开谷歌浏览器时出错
- java - Http Post的响应码是415,如何让响应码变成200
- android - 如何提取消息标题和正文形式 OneSignal 推送通知 Flutter
- php - 获取包含父母、孩子和元数据的帖子类型
- multicast - Ghost 12 - 不能跨子网多播
- python - pip install regex 无法在 Anaconda python3.6.9 virtualenv 上构建
- go - 如何在 Go 中正确编写 JVM AES/CFB8 加密
- python-3.x - TypeError: unhashable type: 'numpy.ndarray' 合并来自 BigQuery 的 pandas 数据帧时