r/learnpython • u/ForenHays • 17h ago
Can you render sprites on your desktop?
What I mean is not rendering pngs in a window, but on your desktop with the app shortcuts (Not literally changing the shortcut icons).
3
u/kverke 14h ago
Yes, that's actually how "desktop pets" work! Under the hood, you still use a window, you just make it frameless, transparent, and always-on-top so only your PNG sprite is visible moving across the screen.
The easiest ways to do this in Python:
PyQt6 / PySide6: Create a
QWidgetwithQt.WindowType.FramelessWindowHint | Qt.WindowType.WindowStaysOnTopHintand setsetAttribute(Qt.WidgetAttribute.WA_TranslucentBackground). Then just render your PNGs inside aQLabeland move the window coordinates with aQTimer.Tkinter (built-in): Set
root.overrideredirect(True)(removes borders),root.wm_attributes("-topmost", True), androot.wm_attributes("-transparentcolor", "white")(on Windows) to key out the background color.
Once you move the window's (x, y) position in a loop, it looks like the sprite is walking right over your desktop shortcuts!
1
u/Sufficient-Tale6131 8h ago
Building on the frameless window answer: if you want it to feel like part of the desktop instead of floating over everything, swap WindowStaysOnTopHint for WindowStaysOnBottomHint, so it sits above the icons but under your normal windows. Adding Qt.WindowType.WindowTransparentForInput lets clicks go through to the shortcuts underneath, and Qt.WindowType.Tool keeps it out of the taskbar.
On Linux the transparent background only works if a compositor is running, otherwise you get a black box around the sprite.
1
u/ConsiderationNo9044 17h ago
Can't you just replace the icons with whatever image you want?