Python-Tkinter:how to highlight item on taskbar on windows xp when window is minimized to the taskbar
Asked Answered
A

3

3

i am using python/tkinter to write a IM software on XP. now i've got all the main functions done except i don't know how to highlight or change colour my IM item on taskbar on windows xp when window is minimized to the taskbar when a new message is received. i've search for this but just got c# solution. i need help on python. thanks!

Altruistic answered 20/11, 2012 at 17:2 Comment(0)
S
3

I needed to do this for a tkinter python slack client I am writing and found http://wiki.tcl.tk/1049 . After a bit of guessing, I found that

Tk().deiconify()
Tk().focus_force()

(i.e. on the root window) does the trick. Windows doesn't actually change the focus and show the window since applications are not allowed to do that (Windows after XP) but it flashes the taskbar instead. It will keep flashing until clicked on but that seems to be the behaviour of Skype/Slack etc. Certainly close enough for many uses.

Obviously this is an old question but I couldn't find a concise, python only, answer and still needed one!

Schweinfurt answered 13/9, 2016 at 10:44 Comment(1)
In windows 10 this steals the focus from the current active window, this looks different from the behavior reported in Windows XPToby
P
0

I'm not sure if there is a good way of doing this with Tk. Maybe somebody more knowledgeable will be able to point you in a better direction. Since Python is so dependent on OO, you may have a difficult time writing bindings to the Windows window manager.

If you don't find anything else, I did stumble on http://wiki.tcl.tk/4089, which manages Windows icons on the taskbar. Perhaps you could utilize this to simulate the taskbar flash that you want?

Pentheam answered 20/11, 2012 at 17:39 Comment(0)
D
0

I think you have to use the pywin32 module for this. This is the only way I could get it to work:

import pywin32gui
import tkinter as tk

window = tk.Tk()

... etc ...

# Highlight the window on taskbar:
hwnd_int = int(window.frame(), base=16)
win32gui.FlashWindow(hwnd_int, 0)
Darksome answered 19/1 at 15:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.