gpt4 book ai didi

python - 如何在 Canvas 项目中插入图像?

转载 作者:行者123 更新时间:2023-12-04 16:42:29 27 4
gpt4 key购买 nike

我正在为学校设计一个游戏项目,看起来像这样:游戏中方面

 In-game aspect

我已经创建了这些彩色多边形,如下所示:

ship = can.create_polygon(410,650,450,600,490,650 , fill= 'red' , outline='black')

ennemies = can.create_rectangle(x-r, y-r, x+r, y+r, fill='green')

所以现在我想用我自己的图像将 填充到中。那可能吗 ?如何 ?

最佳答案

from tkinter import *

# create the canvas, size in pixels
canvas = Canvas(width=300, height=200, bg='black')

# pack the canvas into a frame/form
canvas.pack(expand=YES, fill=BOTH)

# load the .gif image file
gif1 = PhotoImage(file='small_globe.gif')

# put gif image on canvas
# pic's upper left corner (NW) on the canvas is at x=50 y=10
canvas.create_image(50, 10, image=gif1, anchor=NW)

# run it ...
mainloop()

关于python - 如何在 Canvas 项目中插入图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43009527/

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