14

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).

Doktor J
  • 1,058
  • 1
  • 14
  • 33

2 Answers2

13

This is the simplest solution I could come up with:

import ctypes
ctypes.windll.user32.FlashWindow(ctypes.windll.kernel32.GetConsoleWindow(), True )
ubershmekel
  • 11,864
  • 10
  • 72
  • 89
7

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.

Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
  • This worked great for me, thanks! I know flashing the taskbar is often considered bad design, but my particular application is strictly for use at work, and my coworkers who would be using it wish to be alerted immediately when my app's finished pulling down its data. – Doktor J Sep 13 '10 at 21:34