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()
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 类。如果调用时只作为两个参数,会假定第二个参数是你文件的文件路径:
myImage = Image(Point(5,5), 'myimage.png')
以下工作正常,但我认为 Tkinter(graphics.py 使用的)不支持 png 文件格式。我不得不使用 gif。
import graphics
from graphics import *
window = GraphWin("gameWindow", 800, 600)
myImage = Image(Point(5,5), "myimage.gif")
myImage.draw(window)
window.mainloop()