Importing custom images into graphics.py

断了今生、忘了曾经 提交于 2019-12-23 04:14:07

问题


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()

回答1:


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')

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()


来源:https://stackoverflow.com/questions/19249859/importing-custom-images-into-graphics-py

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!