我编写了一个python代码,用于将随机文本输入.txt文件。现在,我想通过“通知-发送”命令将这个随机文本发送到通知区域。我们该怎么做?
发布于 2012-02-29 09:16:50
我们总是可以调用通知-发送作为子进程,例如:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import subprocess
def sendmessage(message):
subprocess.Popen(['notify-send', message])
return或者,我们也可以安装python-通知2或丙酮3-通知2,并通过以下方式调用通知:
import notify2
def sendmessage(title, message):
notify2.init("Test")
notice = notify2.Notification(title, message)
notice.show()
return发布于 2015-10-26 10:01:42
要回答Mehul Mohan问题,并建议以最短的方式推送带有标题和消息部分的通知:
import os
os.system('notify-send "TITLE" "MESSAGE"')由于引号中的引号,将其放入函数中可能会有些混乱。
import os
def message(title, message):
os.system('notify-send "'+title+'" "'+message+'"')发布于 2018-10-15 21:35:30
您应该使用notify2包,它是python的替代品。如下所示使用它。
pip install notify2守则如下:
import notify2
notify2.init('app name')
n = notify2.Notification('title', 'message')
n.show()https://askubuntu.com/questions/108764
复制相似问题