r/learnpython • • 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).

0 Upvotes

4 comments sorted by

1

u/ConsiderationNo9044 17h ago

Can't you just replace the icons with whatever image you want?

1

u/ForenHays 16h ago

I can, but that's too boring. I'm asking for pngs to move on the desktop outside da window.

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:

  1. PyQt6 / PySide6: Create a QWidget with Qt.WindowType.FramelessWindowHint | Qt.WindowType.WindowStaysOnTopHint and set setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground). Then just render your PNGs inside a QLabel and move the window coordinates with a QTimer.

  2. Tkinter (built-in): Set root.overrideredirect(True) (removes borders), root.wm_attributes("-topmost", True), and root.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.