Perspective Textfield not getting focus after setting display True

I have a Textfield with a message handler on it. The message handler sets the display property of the Textfield to True and then calls self.focus(). The problem is the Textfield does not seem to be getting focus after the handler runs.

If i change the Textfield’s display property to always be True, the the handler’s focus seems to work fine. Do I some how need to put in a delay for the Textfield to become True first then run a script to set focus on the Textfield?

Does some other component receive focus? Is there ever a situation where multiple components receive focus at the same time?

no, I only have a button and this textfield. This text field is the only thing setup to call self.focus()

Ok, I verified this behavior and it does seem to be a timing issue. I tested your script but with 1/8th of a second delay and the focus behaved normally.

import time

self.position.display = True

The effect is close to what you want. You may be able to get an even faster focus.

By the way, if anyone else was wondering, the same thing happens when using meta.visible instead of position.display - the text field will still not focus.

EDIT: I’m not saying this is the solution, this is only a simple test. I don’t know what’s actually causing this behavior. It might have to do with multithreading or some race conditions.