这似乎是一个非常简单的问题,但当单击按钮时,我无法显示jpg图像。这是我的代码(为了时间的缘故没有按钮代码):
from tkinter import *
#screen stuff here
canvas = Canvas(app)
canvas.grid(row = 0,column = 0)
photo = PhotoImage(file = "test.jpg")
canvas.create_image(0,0, image = photo)
def show_image():
global canvas
global photo
canvas.create_image(0,0, image = photo)
#button that calls the function down here
谢谢!
这适用于Python2:
在Python3中,
PhotoImage
can open GIF, PPM/PGM images。要打开其他格式,可以need to install Pillow(Python3的PIL项目的一个分支)。相关问题 更多 >
编程相关推荐