Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make a Python console application flash in the taskbar in Windows?

Is there a way to make my Python console application's window flash in the Windows taskbar, to get a user's attention?

My script will be run exclusively in a relatively homogeneous Windows environment, so I don't care about detecting whether a particular API is present, or whether a solution is cross-platform or not (of course cross-platform is better for future reference... but I don't need it for this application).

like image 656
Doktor J Avatar asked Jul 15 '10 18:07

Doktor J


3 Answers

This is the simplest solution I could come up with:

import ctypes
ctypes.windll.user32.FlashWindow(ctypes.windll.kernel32.GetConsoleWindow(), True )
like image 154
ubershmekel Avatar answered Oct 20 '22 01:10

ubershmekel


Flashing the taskbar in Windows is accomplished using the FlashWindowEx API function (Python API help).

I haven't tried this myself, but it should be possible to call this function from Python using PyWin32 (Python for Windows extensions) that can either by installed manually or by installing ActivePython.

like image 34
Dirk Vollmar Avatar answered Oct 20 '22 00:10

Dirk Vollmar


Would this work? http://docs.activestate.com/activepython/2.4/pywin32/win32gui__FlashWindow_meth.html

like image 31
shookster Avatar answered Oct 20 '22 00:10

shookster