为了账号安全,请及时绑定邮箱和手机立即绑定

PySimpleGUI 输出元素换行符

PySimpleGUI 输出元素换行符

白猪掌柜的 2023-05-23 15:07:19
我正在使用 PySimpleGUI 作为 tkinter 包装器,它就像一个魅力,但是:当我向输出元素打印某些内容时,只要达到每行给定的字符限制,它就会执行换行符。当它不能用剩余的行长度完全显示当前单词时,我可以以某种方式将它更改为断行吗?干杯编辑样本图像:
查看完整描述

1 回答

?
千巷猫影

TA贡献1829条经验 获得超7个赞

该元素具有元素Output属性。而 element的属性实际上是 tkinter对象,您可以使用它来配置包装模式。TKOutTKOutputoutputTKOutputText


下面是一个简单的例子:


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()

输出:

//img1.sycdn.imooc.com//646c66500001369306130450.jpg

查看完整回答
反对 回复 2023-05-23
  • 1 回答
  • 0 关注
  • 138 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信