【发布时间】:2018-11-13 18:41:55
【问题描述】:
有没有办法在 tkinter 画布中显示图像,以便它出现在同一个 tkinter 画布中创建的按钮上?我的代码如下所示:
从 tkinter 导入 *
root = Tk()
canvas = Canvas(root, bg="red")
button = Button(canvas, text="Example")
image = PhotoImage(file="image")
canvas.pack()
button.grid(row=0, column=0)
canvas.create_image(0, 0, image=image)
root.mainloop()
但是,这仅显示按钮而不显示图像。我该如何解决这个问题?
注意:该解决方案必须使用 Python 自带的默认模块(因此没有 PIL),因为该程序需要在我无法下载其他模块的环境中使用。
【问题讨论】: