Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SytanxError with sg. argument from PySimpleGUI in Python

I want to make a widget window, but the Bottom and Text part aren’t working properly and it keps getting sintax errors at the same part:

import PySimpleGUI as sg

layout = [
    [sg.Text("Hello from PySimpleGUI")], 
    [sg.Button("Close")]
    window = sg.Window("Demo, layout")
]
while true:
    event, values = window.read()
    if event == "Close" or event == sg.WIN_CLOSED:
        break

window.close()

it says I forgot a comma, but the references I checked for this code didn’t use one, and I tried changing the elements or just putting the comma, but it didn’t work either.

ERROR message:

line 5
    [sg.Buttom("OK")]
    ^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This:

layout = [
    [sg.Text("Hello from PySimpleGUI")], 
    [sg.Button("Close")]
    window = sg.Window("Demo, layout")
]

isn’t a valid list, because you can’t include an assignment like that, and there should be a comma after the second element. Also, the call to sg.Window() doesn’t look right, because presumably you meant to pass layout as the second argument to define the layout of a window named "Demo".

Try doing this:

layout = [
    [sg.Text("Hello from PySimpleGUI")], 
    [sg.Button("Close")]
]
window = sg.Window("Demo", layout)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading