I'm using the PySimpleGUI library, and trying to make a GUI (code below) to input a codeword puzzle (essentially the same format as a crossword). I want my GUI to be an array of textboxes of specified dimensions that can take a number or letter.
It builds a GUI of the correct format (built GUI), but when I enter the numbers 1-9 in each box (filled GUI) and click "OK", the output printed to the console is: "7,8,9,,,,,,,", so I assumed it is only reading the last set of inputs. If I leave the last row blank and fill the top two rows as before, I get ",,,,,,,,," outputted to the console. I tried changing the list comprehensions to for loops and got the same result, but when I hardcoded the layout (code below) and entered in 1-9, I got the desired "1,2,3,4,5,6,7,8,9,". How do you implement a layout for a PySimpleGUI using a variable(s)?
# original code
import PySimpleGUI as sg
def entryGUI(length, width):
line = [sg.InputText('', size=(3, 1)) for i in range(length)]
entryLayout = [line for i in range(width)]
entryLayout.append([sg.CloseButton("OK"), sg.CloseButton("Cancel")])
entryWin = sg.Window("CodeWord Solver").Layout(entryLayout)
button, values = entryWin.Read()
for value in values:
print(value + ",", end="")
entryGUI(3, 3)
# hardcoded code
import PySimpleGUI as sg
def entryGUI(length, width):
entryLayout = [
[sg.InputText('', size=(3, 1)), sg.InputText('', size=(3, 1)), sg.InputText('', size=(3, 1))],
[sg.InputText('', size=(3, 1)), sg.InputText('', size=(3, 1)), sg.InputText('', size=(3, 1))],
[sg.InputText('', size=(3, 1)), sg.InputText('', size=(3, 1)), sg.InputText('', size=(3, 1))],
[sg.CloseButton("OK"), sg.CloseButton("Cancel")]
]
entryWin = sg.Window("CodeWord Solver").Layout(entryLayout)
button, values = entryWin.Read()
# if button != "OK":
# exit()
# else:
for value in values:
print(value + ",", end="")
#return values
entryGUI(3, 3)