Changed enter_submits to True so that the bind_return_key works correctly.

This commit is contained in:
PySimpleGUI 2023-04-26 09:47:14 -04:00
parent fb5fdbdd5c
commit cb0da5887d
1 changed files with 7 additions and 4 deletions

View File

@ -4,25 +4,28 @@ import PySimpleGUI as sg
''' '''
A simple send/response chat window. Add call to your send-routine and print the response A simple send/response chat window. Add call to your send-routine and print the response
If async responses can come in, then will need to use a different design that uses PySimpleGUI async design pattern If async responses can come in, then will need to use a different design that uses PySimpleGUI async design pattern
Copyright 2023 PySimpleGUI
''' '''
sg.theme('GreenTan') # give our window a spiffy set of colors sg.theme('GreenTan') # give our window a spiffy set of colors
layout = [[sg.Text('Your output will go here', size=(40, 1))], layout = [[sg.Text('Your output will go here', size=(40, 1))],
[sg.Output(size=(110, 20), font=('Helvetica 10'))], [sg.Output(size=(110, 20), font=('Helvetica 10'))],
[sg.Multiline(size=(70, 5), enter_submits=False, key='-QUERY-', do_not_clear=False), [sg.Multiline(size=(70, 5), enter_submits=True, key='-QUERY-', do_not_clear=False),
sg.Button('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True), sg.Button('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True),
sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]] sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]]
window = sg.Window('Chat window', layout, font=('Helvetica', ' 13'), default_button_element_size=(8,2), use_default_focus=False) window = sg.Window('Chat window', layout, font=('Helvetica', ' 13'), default_button_element_size=(8,2), use_default_focus=False)
while True: # The Event Loop while True: # The Event Loop
event, value = window.read() event, values = window.read()
if event in (sg.WIN_CLOSED, 'EXIT'): # quit if exit button or X if event in (sg.WIN_CLOSED, 'EXIT'): # quit if exit button or X
break break
if event == 'SEND': if event == 'SEND':
query = value['-QUERY-'].rstrip() query = values['-QUERY-'].rstrip()
# EXECUTE YOUR COMMAND HERE # EXECUTE YOUR COMMAND HERE
print('The command you entered was {}'.format(query), flush=True) print('The command you entered was {}'.format(query), flush=True)
window.close() window.close()