亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

輸出:

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

查看完整回答
反對 回復 2023-05-23
  • 1 回答
  • 0 關注
  • 214 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號