How to fix nonetype object non subscriptable error in PySimpleGUI?

When I close this window, this error shows up. All I know is that the window.read() returns (None, None), but I do not know what to do to fix this, because it is too confusing. Is there any way how to fix this. Make it as clear and easy to understand as possible.

import PySimpleGUI as sg

sg.theme('DefaultNoMoreNagging')

items_files = [  [sg.Button(pad = (0, 0), tooltip = 'Delete from Frontmost', key = 'DelF')]  ]

tab2 = [  [sg.Button(key = 'Rect', pad = (0, 0), tooltip = 'Rectangle')]  ]

BC = 'white'
CW = 600
CH = 450
LXM = (CW / 2)
LYM = (CH / 2)

mid_left = [  [sg.Text(text = "X:"), sg.Input(default_text = "0", key = "TLX", size = (3, 1))],
              [sg.Text(text = "Y:"), sg.Input(default_text = "0", key = "TLY", size = (3, 1))],
              [sg.Text(text = "Scale X:"), sg.Input(default_text = "0", key = "TSX", size = (3, 1))],
              [sg.Text(text = "Scale Y:"), sg.Input(default_text = "0", key = "TSY", size = (3, 1))]  ]

can = sg.Canvas(size = (CW, CH), background_color = BC, border_width = 1, key = "canvas")

mid_screen = [  [sg.Frame("Insert Values", mid_left, expand_x = True, expand_y = True), can]  ]

layout = [  [sg.Frame("", items_files, pad = (1, 1), expand_x = False, expand_y = False), sg.TabGroup([[sg.Tab('Insert', tab2)]])],
            [mid_screen]  ]
window = sg.Window('title', layout, finalize = True)
tkc = can.TKCanvas

N = 0

OL = [0]

while True:
    event, values = window.read()
    TLX = values["TLX"]
    TLY = values["TLY"]
    TSX = values["TSX"]
    TSY = values["TSY"]
    LT = 1
    FC = 'red'
    LC = 'black'

    def MakeRect():
        pum = N
        OL.insert(pum, tkc.create_rectangle((float(LXM) + float(TLX) + float(TSX)), (float(LYM) + float(TLY) + float(TSY)), (float(LXM) + float(TLX) - float(TSX)), (float(LYM) + float(TLY) - float(TSY)), fill = FC, outline = LC, width = LT,  tag = pum))
        pum = N + 1
        return pum

    def DeleteObj():
        pum = N
        tkc.delete(OL[pum])
        del OL[pum]
        pum = N - 1

    if event == 'Rect':
        MakeRect()
        print (OL)
        print (N)

    if event == 'DelF':
        DeleteObj()
        print (OL)
        print (N)
    
    if event in (sg.WIN_CLOSED, 'Exit'):
        break

window.close()

Here’s the error text:

Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Help.py", line 34, in <module>
    TLX = values["TLX"]
TypeError: 'NoneType' object is not subscriptable

Put this just after the line that has the window.read():

    if event is None:
        break

Or add None to the current break condition and move it up just after the read.

    event, values = window.read()
    if event in (None, sg.WIN_CLOSED, 'Exit'):
        break

What do you think it should return instead? Why do you think it should return that? When you get this (None, None) result from it, what do you think it means? If you do not know/understand, did you try to read the documentation in order to figure it out? (More generally, do you understand what None means in Python?) Can you think of a way to write code to check whether there was a result like that? What should happen when you get that result? What happens if you try checking for that result, handling it in the appropriate way, and then using the rest of the code when you get an ordinary result?