Skip to content

Instantly share code, notes, and snippets.

@israel-dryer
Last active September 5, 2020 08:45
Show Gist options
  • Save israel-dryer/8d014a61cdce4ef256c70c3bb4cab1e6 to your computer and use it in GitHub Desktop.
Save israel-dryer/8d014a61cdce4ef256c70c3bb4cab1e6 to your computer and use it in GitHub Desktop.
How to disable word-wrap in PySimpleGUI output
import PySimpleGUI as sg
# create output element
output = sg.Output(size=(50, 15))
# button to initiate text printing
button = sg.Button('Print long text', key='-BTN-')
# set the layout
layout = [[output], [button]]
# create and finalize window
window = sg.Window('Output Testing', layout, finalize=True)
# turn off the word wrap (options include 'none', 'char', 'word')
output._TKOut.output.configure(wrap='none')
# run event loop
while True:
event, values = window.read()
if event is None:
break
elif event == '-BTN-':
text = help(button)
print(text)
window.close()
@PySimpleGUI
Copy link

Lately I've been suggesting users switch over to the Multiline Element rather than the Output element. The reason is that there are many more options on the Multiline versus the Output element.

There is an option to re-route stdout in the Multiline Element now so your layout code is minimally impacted to make the switch. Simply set reroute_stdout=True when specifying the Multiline in the layout.

You should be able to use the same trick to disable wrapping with this line of code when using a Multiline Element.

window['MULTILINE KEY'].Widget.configure(wrap='none')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment