And added a comment to the code.
When starting the program, sometimes the window was displayed incorrectly.
Reworked the architecture.