Wednesday, May 1, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  81] [ 0]  / answers: 1 / hits: 49254  / 3 Years ago, sat, july 31, 2021, 1:24:47

I wrote a python code for getting random text into a .txt file.
Now I want to send this random text into notification area via 'notify-send' command.
How do we do that?


More From » python

 Answers
7

We can always call notify-send as a subprocess, e.g like that:


#!/usr/bin/env python
#-*- coding: utf-8 -*-

import subprocess

def sendmessage(message):
subprocess.Popen(['notify-send', message])
return

Alternatively we could also install python-notify2 or python3-notify2 and call the notification through that:


import notify2

def sendmessage(title, message):
notify2.init("Test")
notice = notify2.Notification(title, message)
notice.show()
return

[#40111] Sunday, August 1, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adedes

Total Points: 454
Total Questions: 114
Total Answers: 111

Location: Turks and Caicos Islands
Member since Fri, May 8, 2020
4 Years ago
;