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
相关产品推荐
相关产品推荐

