Search code examples
pysimplegui

PySimpleGUI | Whats the difference between window() and window.read()?


I was coding a gui from memory and accidentally used the following line in my event loop:

event, value = window()

The proper way is shown as:

event, value = window.read()

Calling print on each one returns the same thing:

window()=('OK', {0: 'asd'})
window.read()=('OK', {0: 'asd'})

Is there a difference? My gui worked perfectly fine. I tried a couple of different tests to break it or figure out what the difference was and couldn't.


Solution

  • Actually, both of them are the same.

        def __call__(self, *args, **kwargs):
            """
            Call window.read but without having to type it out.
            window() == window.read()
            window(timeout=50) == window.read(timeout=50)
    
            :return: The famous event, values that read returns.
            :rtype:  Tuple[Any, Dict[Any, Any]]
            """
            return self.read(*args, **kwargs)