开发者

How to show the default beautiful popup message in ubuntu using python?

开发者 https://www.devze.com 2023-03-12 02:05 出处:网络
http://tinypic.com/r/5dv7kj/7 How can i show the message like in the picture(top right)? I\'m new to linux and now tring to use pygtk to make a client application to show/popup some random hint/mems.

http://tinypic.com/r/5dv7kj/7 How can i show the message like in the picture(top right)?

I'm new to linux and now tring to use pygtk to make a client application to show/popup some random hint/mems.

Using traditional winodw is OK,but this one is much more friendly to me.I have tried scanning through the pygtk guide but still missing the solution.Other

开发者_如何学编程Is there any body could give me some hint?Any python GUI libs are also OK.


It's an Ubuntu specific thing called NotifyOSD. There are examples of programming for it here.


Quick and Dirty codes in python

import pynotify

# Only Text Notification
pynotify.init('Basic')
pynotify.Notification("Title", "simple text").show()


# Lets try with an image
pynotify.init('Image')
## Use absolute Path of the photo
pynotify.Notification("Title", "My Photo here!!", "/home/nafis/Pictures/me.png").show()

# Try Markup 
pynotify.init("markup") ## all smallerCase "markup"
# but in parameter, first letter capital  
pynotify.Notification("Markup", 
  '''
  <b>bold</b>, <i>italic</i>, <u>underline</u>
  and even <a href="http://google.com">links</a> are supported!
  '''
).show()

Also You can use it from shell (I use lubuntu, it works here.)

#!/bin/bash
### try it in terminal

notify-send -t 900 "Title" "Message"


A simple method without any additional packages.
you can execute commands via os.system.

import os

def message(title, message):
  os.system(f"notify-send '{title}' '{message}'")

message("Title", "Im message")
0

精彩评论

暂无评论...
验证码 换一张
取 消