Question

Is it possible to produce an alert similar to JavaScript's alert("message") in python, with an application running as a daemon.

This will be run in Windows, Most likely XP but 2000 and Vista are also very real possibilities.

Update:
This is intended to run in the background and alert the user when certain conditions are met, I figure that the easiest way to alert the user would be to produce a pop-up, as it needs to be handled immediately, and other options such as just logging, or sending an email are not efficient enough.

Was it helpful?

Solution

what about this:

import win32api

win32api.MessageBox(0, 'hello', 'title')

Additionally:

win32api.MessageBox(0, 'hello', 'title', 0x00001000) 

will make the box appear on top of other windows, for urgent messages. See MessageBox function for other options.

OTHER TIPS

GTK may be a better option, as it is cross-platform. It'll work great on Ubuntu, and should work just fine on Windows when GTK and Python bindings are installed.

from gi.repository import Gtk

dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO,
            Gtk.ButtonsType.OK, "This is an INFO MessageDialog")
dialog.format_secondary_text(
    "And this is the secondary text that explains things.")
dialog.run()
print "INFO dialog closed"

You can see other examples here. (pdf)

The arguments passed should be the gtk.window parent (or None), DestroyWithParent, Message type, Message-buttons, title.

You can use win32 library in Python, this is classical example of OK or Cancel.

import win32api
import win32com.client
import pythoncom

result = win32api.MessageBox(None,"Do you want to open a file?", "title",1)

if result == 1:
 print 'Ok'
elif result == 2:
 print 'cancel'

The collection:

win32api.MessageBox(0,"msgbox", "title")
win32api.MessageBox(0,"ok cancel?", "title",1)
win32api.MessageBox(0,"abort retry ignore?", "title",2)
win32api.MessageBox(0,"yes no cancel?", "title",3)

Start an app as a background process that either has a TCP port bound to localhost, or communicates through a file -- your daemon has the file open, and then you echo "foo" > c:\your\file. After, say, 1 second of no activity, you display the message and truncate the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top