0

i am using PySimpleGUI as a tkinter wrapper and it works like a charm, but:

When i am printing something to the output element it performs a linebreak whenever the given character limit per line is reached.

Can i somehow change it to break line when it can't display the current word fully with the remaining line length?

Cheers

EDIT for sample image:

Error_Sample

Sascha Höche
  • 66
  • 1
  • 8
  • 2
    Please include some code to understand it better – Delrius Euphoria Aug 14 '20 at 14:35
  • Don't know what code would clarify so i added a picture. – Sascha Höche Aug 14 '20 at 14:54
  • What would qualify would be something runnable that reproduces the problem. – martineau Aug 14 '20 at 15:22
  • I've never used pysimplegui, but the tkinter text widget supports word wrapping. Do you have the ability to directly configure the text widget? – Bryan Oakley Aug 14 '20 at 15:31
  • @BryanOakley the Output Element doesn't seem to have this property. – Sascha Höche Aug 14 '20 at 15:42
  • Yes, but you've tagged this with `tkinter` so I'm assuming that tkinter is used as the backend. The question I asked was whether you can get a reference to the underlying tkinter widget. – Bryan Oakley Aug 14 '20 at 15:45
  • @BryanOakley PySimpleGUI wraps the tkinter module that is why i tagged it. Sadly i have no further experience in GUI programming, since i usually work in data science and ML only so i can't really answer your question. – Sascha Höche Aug 14 '20 at 15:48
  • The `Output` element has a property `TKOut` which is `TKOutput` element. And the attribute `output` of `TKOutput` element is actually tkinter `Text` object. – acw1668 Aug 14 '20 at 16:04
  • Using the Multiline Element would work best for this as it's already setup to wrap at the "word" level. You can now re-route stdout to a multiline element as well. – Mike from PSG Aug 14 '20 at 18:57

1 Answers1

1

The Output element has a property TKOut which is TKOutput element. And the attribute output of TKOutput element is actually tkinter Text object which you can use to configure the wrapping mode.

Below is an simple example:

import PySimpleGUI as sg

layout = [
    [sg.Text('GameFinder', font=('Helvetica', 24, 'bold'))],
    [sg.In(key='-IN-', size=(40,1)), sg.Button('Search')],
    [sg.Output(key='-OUT-', size=(80, 20))],
]

window = sg.Window('Game Finder', layout, element_justification='center').finalize()
window['-OUT-'].TKOut.output.config(wrap='word') # set Output element word wrapping

print('''
i am using PySimpleGUI as a tkinter wrapper and it works like a charm, but:

When i am printing something to the output element it performs a linebreak whenever the given character limit per line is reached.

Can i somehow change it to break line when it can't display the current word fully with the remaining line length?

Cheers
''')

while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED:
        break

window.close()

And the output:

enter image description here

acw1668
  • 40,144
  • 5
  • 22
  • 34