Reputation: 1
So I'm trying to get the GUI up and running for a simple program that will check a modbus network. Which needs a giant text field to display data. I am using sg.Text. The problem I have is the text box doesn't append when updating. I am sure I am missing something obvious. I need to append because of how the program will check the network and then maybe save the entire text box. How do I make is scrollable as well? I feel like I having a massive brain fart.
import PySimpleGUI as sg
import os.path
# First the window layout in 2 columns
file_list_column = [
[
sg.Text("Search Network?"),
sg.Button('Read Serial'),
sg.Button('Test Modbus'),
],
[
sg.Text("Textbox test.", size=(30, 5), relief=sg.RELIEF_SUNKEN, background_color='white', text_color='black',
enable_events=True, key="-NETWORK LIST-")
],
[
sg.Input(key='-IN-')
],
[
sg.Button('Test'),
sg.Button('Clear'),
sg.Button('Exit')
],
]
# ----- Full layout -----
layout = [
[
sg.Column(file_list_column),
sg.VSeperator(),
]
]
window = sg.Window("Network Troubleshooter", layout)
# Run the Event Loop
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED:
break
if event == 'Test':
# Update the "output" text element to be the value of "input" element
window['-NETWORK LIST-'].update(values['-IN-'])
if event == 'Clear':
# Update the "output" text element to be the value of "input" element
window['-NETWORK LIST-'].update('')
window.close()
Upvotes: 0
Views: 6287
Reputation: 13061
sg.Text
is a label, no append function. You can do it by adding string to the current value of the displayed text, then update it.
text = window['-NETWORK LIST-']
text.update(text.get()+'New Text append')
There's no scroll bar for element sg.Text
, sg.Multiline
is preferred and same way to append text.
Upvotes: 4