Last active
September 5, 2020 08:45
-
-
Save israel-dryer/8d014a61cdce4ef256c70c3bb4cab1e6 to your computer and use it in GitHub Desktop.
How to disable word-wrap in PySimpleGUI output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 theMultiline
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.