我正在编写一个聊天程序,用的是tkinter,希望能够在收到消息的时候,使任务栏处的窗口闪动一下(就像微信和qq收到消息后一样)。如何做到闪动一下窗口?
1条回答 默认 最新
- Smart-Space 2022-08-22 11:01关注
可以使用winapi(user32)的FalshWindow功能。
下面是示例:from tkinter import * from tkinter import ttk from ctypes import * u32=windll.user32 def test(): u32.FlashWindow(u32.GetParent(r.winfo_id()),True) print('yes') r=Tk() r.title('test tkinter') r.after(3000,test) r.mainloop()
当窗口没有焦点时,会触发
FlashWindow
。如果想要定义更多内容,可以使用FalshWindowEx
。
关于后者,见https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-flashwindowex本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用