如何在画布项目中插入图像? [英] How to insert an image in a canvas item?
本文介绍了如何在画布项目中插入图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为学校做一个游戏项目,它看起来像这样:游戏内方面
I am working on a game project for school, which look like this : In-game aspect
我像这样创建了这些彩色多边形:
I have created these colored polygons like this :
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')
所以现在我想用我自己的图像填充他们.那可能吗 ?以及如何?
So now i want to fill them with my own image. Is that possible ? And how ?
推荐答案
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()
这篇关于如何在画布项目中插入图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文