Its fairly common in a number of GUI’s that you can’t actually call anything creating a UI item from within an event, try just setting a flag in the event and responding to the flag in your main loop…
You currently need to create a ‘fiber’ inside event handlers if you are writing blocking code, as event handlers run on the main thread and you can’t block the main thread or the entire app will halt.