gpt4 book ai didi

python - 在 Pysimplegui 中在图像上绘制矩形

转载 作者:行者123 更新时间:2023-12-02 19:55:30 24 4
gpt4 key购买 nike

我希望使用 Pysimplegui 在图像上绘制一个矩形。我尝试使用 Graph 对象来完成此操作,但据我所知,您无法对图像对象执行任何操作。我在 Pygame 中找到了替代方案,但我的脚本已经在 pysimplegui 中构建完成。这个功能/演示存在吗?

最佳答案

将图像绘制到graph对象中,然后在顶部绘制矩形:

import PySimpleGUI as sg

layout = [
[
sg.Graph(
canvas_size=(400, 400),
graph_bottom_left=(0, 0),
graph_top_right=(400, 400),
key="graph"
)
]
]

window = sg.Window("rect on image", layout)
window.Finalize()

graph = window.Element("graph")

graph.DrawImage(filename="foo.png", location=(0, 400))
graph.DrawRectangle((200, 200), (250, 300), line_color="red")

while True:
event, values = window.Read()
if event is None:
break

关于python - 在 Pysimplegui 中在图像上绘制矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57191494/

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