0

I am assigning a GUI variable to an excel sheet cell. I use PySimplegui, then read the values of that GUI, and openpyxl to write to my excel sheet. It always tells me

TypeError: 'NoneType' object is not subscriptable

no matter what.

import PySimpleGUI as sg
import openpyxl

wb = load_workbook(filename=template_sheet)
excel_sheet = wb['Sheet 1']

layout = [
sg.Input('Input Address here', key='_address_')
]
window = sg.window(layout)

excel_sheet['F9'] = values['_address_'] # THIS IS THE PROBLEM CHILD

I expect the values['_address_] to be put in cell F9 of the excel sheet. Instead, it just tells me because values['_address_'] is Nonetype (regardless of whether its filled in or not), it does not even try

Kirby Forsberg
  • 124
  • 1
  • 3
  • It's prolly saying that ```values``` is NoneType and that you can't subscript it using ```__address__``` – LazyCoder Jul 30 '19 at 21:47
  • where do you define `values` ? Maybe you have `values = None` and now `values['_address_]` means `None['_address_]` which gives error `'NoneType' object is not subscriptable` – furas Jul 30 '19 at 22:10

1 Answers1

0

You've got 5 problems. Are you looking at the errors and using the sample code?

The first is syntax essentially as there is no sg.window. It's supposed to be sg.Window. You should have gotten an error for that.

Second, you need to add a title to your window. Your code is passing the layout as the title.

Third, you need to call window.Read(). It's where you get the values variable.

Fourth, you are missing a pair of [] around the sg.Input Element.

Fifth, you have no button to trigger the event. The only thing you can do is close the window which will return None for the value of your input element.

The basic design patterns you can copy are in the readme.

import PySimpleGUI as sg
import openpyxl

wb = load_workbook(filename=template_sheet)
excel_sheet = wb['Sheet 1']

layout = [
           [sg.Input('Input Address here', key='_address_')],
           [sg.Button('Go')]
         ]

window = sg.Window('Window title', layout)

event, values = window.Read()

excel_sheet['F9'] = values['_address_'] # THIS IS THE PROBLEM CHILD
Mike from PSG
  • 5,312
  • 21
  • 39
  • I did have all of that. I copied a vague recreation of what was in the code. I have a title, just didn't include it, brackets were correct, Window was correct and i read values, otherwise i wouldnt have gotten a TypeError. It would have been an AttributeError or something else. That is my fault. I poorly copied the code. But the problem stands that the line where it sets the 'value["_address_"]' to cell F9 still does not work – Kirby Forsberg Aug 01 '19 at 12:18
  • 1
    I don't understand why you would post code with FIVE errors that is completely incapable of running. Particularly when you completely missed adding some lines of code. Or I think you did. Did you run the version I took the time to repair? – Mike from PSG Aug 02 '19 at 10:27
  • I was still new to PySimpleGUI. Since then, I fixed this whole issue just by reading the documentation and experimenting with different methods. Looking back on the question and the code I provided, I can 100% see the issue. But in the moment, it was just me being introduced to a lot of new things at once. Thank you for your help. – Kirby Forsberg Mar 09 '20 at 22:35
  • Hey, that's awesome to hear! Glad you've been making progress and great that the documentation helped. That's been quite a number of months you've stuck with it. Nice. – Mike from PSG Mar 11 '20 at 00:55