gpt4 book ai didi

python - pysimplegui 表多行文本处理

转载 作者:行者123 更新时间:2023-12-04 08:35:45 27 4
gpt4 key购买 nike

我正在从日志文件中填充 pySimpleGui 表。大多数日志是单行,但存在一些多行文本。布局中的表格定义如下[sg.Table(key="mainTable",values=data, headings=header_list, display_row_numbers=False,col_widths=size_list,auto_size_columns=False, num_rows=40)]当前多行文本与下一行文本重叠。有没有办法在单个单元格中显示多行文本或文本裁剪是唯一的方法?

最佳答案

如果您查看他们的 QT TableWeb Table接受 auto_size_columns并在表中忽略它,特别是在 QT not using it for Table but for Tree 中和 Web its commented !
检查他们允许的选项并查看我们是否可以申请后setWordWrap直接在 QTTable 或 Widget 上的任何类似内容上,甚至很难找到它。
但另一方面,他们确实有很多示例可以自定义构建表格格式:Demo_Table_Simulation.py
这是我尝试生成自定义表的内容:

#!/usr/bin/env python
import PySimpleGUI as sg
import csv
import math

# Show CSV data in Table
sg.theme('Dark Red')

def table_example():
filename = sg.popup_get_file('addresses.csv', no_window=True, file_types=(("CSV Files","*.csv"),))
# --- populate table with file contents --- #
if filename == '':
return
data = []
header_list = []
button = sg.popup_yes_no('Does this file have column names already?')
if filename is not None:
with open(filename, "r") as infile:
reader = csv.reader(infile)
if button == 'Yes':
header_list = next(reader)
try:
data = list(reader) # read everything else into a list of rows
if button == 'No':
header_list = ['column' + str(x) for x in range(len(data[0]))]
except:
sg.popup_error('Error reading file')
return
sg.set_options(element_padding=(0, 0))

values = []
for row in data:
# Calculate the size of sg.Text based on the length of the text greater than some size
values.append([sg.Text(i, size=(15, math.ceil(1 if len(i) <= 15 else len(i)/15))) for i in row])

# Add a horizontal separator with length and calculate the width
length=15*len(values[0])
values.append([sg.Text('_'*length)])


input_rows = [[sg.Input(size=(15,1), pad=(0,0)) for col in range(4)] for row in range(10)]

layout = values

window = sg.Window('Table', layout, grab_anywhere=False)
event, values = window.read()

window.close()

table_example()
输出如下所示:
enter image description here

关于python - pysimplegui 表多行文本处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64812348/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com