One reason why the original code didn't work is that ui doesn't let you set the anchor point -- if you want the center to be the anchor, you need to set the center again after calling size_to_fit.
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.