将自定义图像导入graphics.py [英] Importing custom images into graphics.py

查看:120
本文介绍了将自定义图像导入graphics.py的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将PNG文件导入 graphics.py 并使用好像它是在 graphics.py 中创建的?

How can I import a PNG-file into graphics.py and use it as if it were created within graphics.py?

import graphics
from graphics import *

window = GraphWin("gameWindow", 800, 600)
myImage = "myimage.png"
myImage.draw(window)
window.mainloop()

推荐答案

您可以使用Image类.如果调用仅作为两个参数,则将假定第二个参数是您文件的文件路径:

You can use the Image class. If the call as only two parameters, will assume that the second parameter is the file path of your file:

myImage = Image(Point(5,5), 'myimage.png')

以下代码工作正常,但我不认为Tkinter(graphics.py使用的东西)支持png文件格式.我必须使用gif.

The following works fine but I don't think Tkinter (what is used by graphics.py) supports png file format. I had to use a gif.

import graphics
from graphics import *

window = GraphWin("gameWindow", 800, 600)
myImage = Image(Point(5,5), "myimage.gif")
myImage.draw(window)
window.mainloop()

这篇关于将自定义图像导入graphics.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆