beeware / toga

A Python native, OS native GUI toolkit.
https://toga.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
4.3k stars 668 forks source link

On Windows, the creation of `MainWindow` renders it in the display without calling `show()` #2653

Closed rmartin16 closed 3 months ago

rmartin16 commented 3 months ago

Describe the bug

On Windows, the MainWindow for an app is shown when it is instantiated instead of when show() is called.

Steps to reproduce

MRE:

import toga

class MyApp(toga.App):
    def startup(self):
        self.main_window = toga.MainWindow(title=self.formal_name)

MyApp("MyApp", "www.example.org").main_loop()

Expected behavior

The window should be shown only after show() is called; at least, this is the behavior on Linux, so everything should at least be consistent.

Screenshots

No response

Environment

Logs

No response

Additional context

No response

freakboy3742 commented 3 months ago

It looks like displaying the form is a side effect of setting the MainForm of the ApplicationContext (see App.set_main_window()).

This was historically required because the Winforms async proactor was bound to the main form; however, this hasn't been true since we merged #2112. I'm in the process of reworking main window handling as allowing background and session-based apps (#2651); I'll fix it there.