-1

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?
Oliveira
  • 3
  • 2
  • You have an assignment statement inside your list. You can't do that. Move the `window = ...` statement to before the list, then add `window` as the last item, and be sure to put a comma after the entry just before it. – Tim Roberts Nov 05 '22 at 18:08
  • @TimRoberts It really was part of the problem, now I got another error, but thanks – Oliveira Nov 05 '22 at 18:12
  • The original error seems to be simply the " was misplaced. `"Demo, layout"` should have been `"Demo", layout`. Window was also moved into layout but seems like main error was the typo. – Mike from PSG Nov 06 '22 at 11:15

2 Answers2

0

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)
sj95126
  • 6,520
  • 2
  • 15
  • 34
0

If you need to access an object in a list, you either need to create it before hand, like this:

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

Or do something ugly that relies on knowing the internal structure, like this:

layout = [
    [sg.Text("Hello from PySimpleGUI")], 
    [sg.Button("Close")],
    [sg.Window("Demo")]
]
window = layout[2][0]
Tim Roberts
  • 48,973
  • 4
  • 21
  • 30