0

My program stub looks like this:

import PySimpleGUI as sg

layout = [[sg.Text("Geheime Nachricht eintippen:")],
          [sg.Multiline(size=(70,4),key="GEHEIM")],
          [sg.Spin([i for i in range(1,26)], initial_value=12, key="SS"), sg.Text("Schlüssel zwischen 1 und 25 wählen")],
          [sg.Radio("Codieren:", "RADIO1", key="XX" ,default=True),
           sg.Radio("Decodieren:","RADIO1", key="YY")],
          [sg.Text("ERGEBNIS:")],
          [sg.Multiline(size=(70,4),key="AUSGABE")],
          [sg.Button("Weiter"), sg.Button("Ende")]]

window = sg.Window("Geheimcode", layout)

while True:  # Ereignisschleife
    event, values  = window.Read()
    geheimertext = values("GEHEIM")
    print(values("GEHEIM"))
    schluessel = int(values["SS"])
    print ("Schlüssel = ", schluessel)
    if values["XX"] == True:
        codedecode = "C"
        print("wir codieren:",codedecode)
    else:
        codedecode = "D"
        print("wir decodieren:",codedecode)
    if event is None or event == "Ende":
        break
window.Close()

The program-line geheimertext = values("GEHEIM") gives this error: TypeError: 'dict' object is not callable I quess that the multiline generates a dictonary in the dictionary values?

so my simple newbie-question is how to read the multiline of a gui made with pysimpleGUI

Kurt
  • 264
  • 1
  • 7
  • 23
  • 1
    The error is happening because you're taking a dictionary (values) and using () after it which looks like a call. The values returned are a dictionary. PRINT the dictionary itself and then determine what to do with the contents of it. This will show you what is returned from a multiline element. – Mike from PSG Mar 18 '20 at 14:11

2 Answers2

0

ok, one possible solution is to iterate over the elements of the multiline:

geheimertext=""
for zeichen in values["GEHEIM"]:
    geheimertext = geheimertext +zeichen    
print(geheimertext)

Is there a better solution? Please teach a newbie

Kurt
  • 264
  • 1
  • 7
  • 23
  • 2
    It is caused by wrong statement `values("GEHEIM")` which is a function call. To get the content of the Multiline element, should use `values["GEHEIM"]` which is index from a dictionary by the element key. Iterate is not necessary here. – Jason Yang Feb 14 '23 at 11:28
0
print(values["GEHEIM"])

values is a dict, and not a callable, so you cannot use () brackets (callables are functions or objects that have a function property). You can access to values through [] brackets. values["GEHEIM"].

Daniel Azemar
  • 478
  • 7
  • 19
  • 1
    For a Multiline element, the entry in the values dictionary is a `string`. Using a `join` is not going to do anything useful. – Mike from PSG Feb 15 '23 at 00:45