问题描述
我试图在主窗口内的画布中显示 .png 图像,但我在画布中得到的只是蓝色背景。请你帮我显示图片而不是蓝色背景?
import os
import tkinter as tk
class MyApplication(tk.Tk):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.title('Program')
self.geometry('500x300')
folder = os.path.dirname(__file__)
self.canvas = tk.Canvas(self,bg='blue',height=300,width=300)
self.canvas.pack()
my_image = tk.PhotoImage(file=folder+'/1102157.png')
self.canvas.create_image(0,anchor = tk.NW,image=my_image)
if __name__=='__main__':
app = MyApplication()
app.mainloop()
我试着放
folder = os.path.dirname(__file__)
在类 MyApplication 之前,但它仍然不起作用。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)