How can I make PySimpleGui read my input and update my window?

We Are Going To Discuss About How can I make PySimpleGui read my input and update my window?. So lets Start this Python Article.

How can I make PySimpleGui read my input and update my window?

  1. How to solve How can I make PySimpleGui read my input and update my window?

    All your problem is that you use .read() in wrong way.
    You have to use only one .read() which returns both values as tuple (event, values)
    event, values = window.read() print('event:', event) print('values:', values)

    Minimal working code (without aiml)
    import PySimpleGUI as sg sg.theme('LightBlue 1') layout = [[sg.Text('You: '), sg.Text(size=(50,1), key='-mytext-')], [sg.Text('Csigusz Foxoup (bot): '), sg.Text(size=(50,1), key='-CSI-')], [sg.Input(key='-myinput-')], [sg.Button('Send message'), sg.Button('Bye!')]] window = sg.Window('Csigusz Foxoup, your friend in a box (bot)', layout, [200,400]) while True: event, values = window.read() print('event:', event) print('values:', values) if event == sg.WIN_CLOSED or event == 'Bye!': break if event == 'Send message': input_text = values['-myinput-'] response = "some response for " + input_text #response = kernel.respond(input_text) window['-mytext-'].update(input_text) window['-CSI-'].update(response) window.close()

  2. How can I make PySimpleGui read my input and update my window?

    All your problem is that you use .read() in wrong way.
    You have to use only one .read() which returns both values as tuple (event, values)
    event, values = window.read() print('event:', event) print('values:', values)

    Minimal working code (without aiml)
    import PySimpleGUI as sg sg.theme('LightBlue 1') layout = [[sg.Text('You: '), sg.Text(size=(50,1), key='-mytext-')], [sg.Text('Csigusz Foxoup (bot): '), sg.Text(size=(50,1), key='-CSI-')], [sg.Input(key='-myinput-')], [sg.Button('Send message'), sg.Button('Bye!')]] window = sg.Window('Csigusz Foxoup, your friend in a box (bot)', layout, [200,400]) while True: event, values = window.read() print('event:', event) print('values:', values) if event == sg.WIN_CLOSED or event == 'Bye!': break if event == 'Send message': input_text = values['-myinput-'] response = "some response for " + input_text #response = kernel.respond(input_text) window['-mytext-'].update(input_text) window['-CSI-'].update(response) window.close()

Solution 1

All your problem is that you use .read() in wrong way.

You have to use only one .read() which returns both values as tuple (event, values)

event, values = window.read()

print('event:', event)
print('values:', values)

Minimal working code (without aiml)

import PySimpleGUI as sg

sg.theme('LightBlue 1')
layout = [[sg.Text('You: '), sg.Text(size=(50,1), key='-mytext-')],
          [sg.Text('Csigusz Foxoup (bot): '), sg.Text(size=(50,1), key='-CSI-')],
          [sg.Input(key='-myinput-')],
          [sg.Button('Send message'), sg.Button('Bye!')]]

window = sg.Window('Csigusz Foxoup, your friend in a box (bot)', layout, [200,400])

while True:
    event, values = window.read()
    print('event:', event)
    print('values:', values)
    
    if event == sg.WIN_CLOSED or event == 'Bye!':
        break
        
    if event == 'Send message':
        input_text = values['-myinput-']
        response = "some response for " + input_text
        #response = kernel.respond(input_text)
        window['-mytext-'].update(input_text)
        window['-CSI-'].update(response)

window.close()

Original Author furas Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment