Amend LD_PRELOAD instead of replacing it, so you can just point it at the right libgtk-4.so while running squares.py from elsewhere.
This shows how to do custom drawing in a widget, implemented in python. The example sets up the environment for running from the toplevel dir, assuming that the build dir is called 'build'.