# How to fix nonetype object non subscriptable error in PySimpleGUI?

**URL:** <https://discuss.python.org/t/how-to-fix-nonetype-object-non-subscriptable-error-in-pysimplegui/27673>\
**Category:** Python Help\
**Created:** [June 11, 2023, 1:06am UTC](https://discuss.python.org/t/how-to-fix-nonetype-object-non-subscriptable-error-in-pysimplegui/27673 "2023-06-11T01:06:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bellkitsu](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@Bellkitsu](https://discuss.python.org/u/Bellkitsu)\
**Post date:** [June 11, 2023, 1:06am UTC](https://discuss.python.org/t/how-to-fix-nonetype-object-non-subscriptable-error-in-pysimplegui/27673/1 "2023-06-11T01:06:04Z")

</div>

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.

```auto
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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![MRAB](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MRAB](https://discuss.python.org/u/MRAB)\
**Post date:** [June 11, 2023, 1:17am UTC](https://discuss.python.org/t/how-to-fix-nonetype-object-non-subscriptable-error-in-pysimplegui/27673/2 "2023-06-11T01:17:04Z")

</div>

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

```auto
    if event is None:
        break

```

---

<div class="post-metadata">

**Author:** ![tjreedy](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/tjreedy/32/137_2.png) [@tjreedy](https://discuss.python.org/u/tjreedy)\
**Post date:** [June 11, 2023, 3:44am UTC](https://discuss.python.org/t/how-to-fix-nonetype-object-non-subscriptable-error-in-pysimplegui/27673/3 "2023-06-11T03:44:01Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![kknechtel](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kknechtel](https://discuss.python.org/u/kknechtel)\
**Post date:** [June 12, 2023, 2:48am UTC](https://discuss.python.org/t/how-to-fix-nonetype-object-non-subscriptable-error-in-pysimplegui/27673/4 "2023-06-12T02:48:37Z")

</div>

> [@Bellkitsu](#):
>
> All I know is that the `window.read()` returns `(None, None)`, but I do not know what to do to fix this

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?
