I wrote a timer/alarm app in Python that I wanted to be accessible from all Windows Desktops. What I had to do until recently was run the app, select the desktops icon on my toolbar, then right click the app and select "Show this window on all desktops". I was certain there was a way I could do it from within the app and after a little research I found it. Here is a function you can call to do this. Note the usually bad practice of using an except
clause to trap all possible errors.
Show your Python app on all Window's desktops
import win32con
import win32gui
def AllDesktops(title):
"""Make the window with the given title visible on all desktops"""
try:
#Get the handle to the window
hwnd = win32gui.FindWindow(None, title)
#Set the WS_EX_TOOLWINDOW style
ex_style = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, ex_style | win32con.WS_EX_TOOLWINDOW)
#Show the window on all desktops
win32gui.SetWindowPos(hwnd, -1, 0, 0, 0, 0,
win32con.SWP_NOMOVE |
win32con.SWP_NOSIZE |
win32con.SWP_SHOWWINDOW |
win32con.SWP_NOZORDER)
return True
except:
return False
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.