You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PySimpleGUI.Input控件设置size参数后高度无法正确调整该如何解决?

问题原因

sg.Input为单行文本输入控件,其size参数仅第一个值(宽度配置)生效,第二个高度参数不会被该控件识别,因此无论你设置多大的高度值,控件都只会保持单行高度。
需要支持多行输入、可调整高度的场景,请使用PySimpleGUI提供的sg.Multiline控件。

修改后可正常运行的代码

import PySimpleGUI as sg

def main():
    # 数据分析录入简易表单
    last_printer = sg.Input(key = 'last_printer', size = (10,1))
    rejected_carts = sg.Input(key = 'rejected_carts', size = (20, 1))
    # 多行输入场景替换为Multiline控件
    notes_for_self = sg.Multiline(key = 'notes_for_self', size = (50,4))
    notes_for_ops = sg.Multiline(key = 'notes_for_ops', size = (50, 4))
    notes_for_escalation = sg.Multiline(key = 'notes_for_escalation', size =(50,4))

    layout = [        
        [sg.Text("Last Printer:"), last_printer],
        [sg.Text("Rejected Cartridges:"), rejected_carts],
        [sg.Text("Notes for Self:"), notes_for_self],
        [sg.Text("Notes for Operators:"), notes_for_ops],
        [sg.Text("Notes for Escalation:"), notes_for_escalation],
        [sg.Submit(), sg.Cancel()]
        ]   

    window = sg.Window("Data Analysis Entry Form", layout)

    event, values = window.read()
    
    window.close()

    print("event is: " + event)
    
    for each in values.items():
        print(each)
if __name__ == '__main__':
    main()

补充说明

如果需要限制Multiline的输入最大长度、是否允许换行、提交逻辑等属性,可以通过配置sg.Multiline的max_length、do_not_clear、enter_submits等参数实现,按需调整即可。

内容的提问来源于stack exchange,提问作者PhasorLaser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 09:51:00