pysimplegui的table里显示图片
时间: 2023-09-18 08:13:20 浏览: 147
layui的table中显示图片方法
可以使用pysimplegui的`Image`元素来显示图片,并将其添加到表格中的单元格中。
以下是一个示例代码,其中包含一个表格,其中包含一些数据和图像:
```python
import PySimpleGUI as sg
# create a list of data that will be shown in the table
data = [
['John', 'Doe', 25, 'male', 'image1.png'],
['Jane', 'Smith', 30, 'female', 'image2.png'],
['Bob', 'Jones', 40, 'male', 'image3.png']
]
# create the layout for the window
layout = [
[sg.Table(values=data,
headings=['First Name', 'Last Name', 'Age', 'Gender', 'Image'],
display_row_numbers=True,
auto_size_columns=False,
col_widths=[10, 10, 5, 6, 15],
justification='left',
num_rows=10,
key='-TABLE-')],
[sg.Button('Exit')]
]
# create the window
window = sg.Window('Table with images', layout)
# loop through the events
while True:
event, values = window.read()
# handle the events
if event == sg.WIN_CLOSED or event == 'Exit':
break
# get the selected row
row = values['-TABLE-'][0]
# get the image filename from the selected row
image_filename = data[row][-1]
# create an Image element and display it in a Popup window
image_element = sg.Image(filename=image_filename)
sg.Popup('Image', image_element)
# close the window
window.close()
```
在此示例中,我们使用`Image`元素显示图像。我们将图像文件名存储在数据列表中,并在单元格中显示它们。如果用户单击表格中的图像单元格,则使用`Popup`窗口显示该图像。
阅读全文