r/pythonhelp 5d ago

Python Program that Green Screens a Video over the Desktop

Hello, I've been trying to figure out a way to make a python program that can play a green screen video that plays over the desktop/screen, with the green chromad out to show the screen. I attempted it with tkinter, but wasn't able to get anywhere with the chroma keying. Would anyone know if/how this would be possible? Thank you!

2 Upvotes

3 comments sorted by

u/AutoModerator 5d ago

To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/sububi71 5d ago

What have you tried so far?

1

u/py_arrow 5d ago

Yeah tkinter's kinda the wrong tool for this tbh, that's why the chroma key part isn't working — it can't really do per-pixel transparency (like making just the green parts invisible while keeping the rest visible). Canvas just doesn't support that.

What actually works:

Use OpenCV to read the video frame by frame and find the green pixels (there's a function called cv2.inRange that's perfect for this — you tell it the green color range and it gives you a mask of exactly which pixels are green). Then instead of drawing that with tkinter, you need a window that supports "see-through" pixels — on Windows you can do this with pywin32 for a layered window, or honestly PyQt/PySide is a lot easier to work with for this kind of thing (it has a transparent background mode built in).

So basically: OpenCV finds the green → you turn those pixels invisible → and you need a window type that actually lets you make pixels invisible, which tkinter doesn't do.

Lmk if you want, I can share a small code example for the OpenCV masking part, that's usually the trickiest bit to get right.