python - Image does not appear on Tkinter -


l have problem tkinter l add image background of frame ,however ,l tried many things nothing show up. l m @ beginning of code , l move on after l overcome problem.

here code:

import tkinter tkinter import *  sc=tk() sc.title("matplotlib") sc.geometry("500x500") img=photoimage("mat.png")  fr1=frame(sc,height=200,bd=5,bg="red",relief=sunken);fr1.pack(side=top,fill=x,expand=1) fr2=frame(sc,height=200,bd=5,relief=sunken);fr2.pack(fill=x,expand=1) fr3=frame(sc,height=200,bd=5,relief=sunken);fr3.pack(side=bottom,fill=x,expand=1) label1=label(fr2,image=img);label1.pack(fill=both)  mainloop() 

how can l solve it? or l not want use other module if possible l m willing use tkinter structure of code

the problem filename isn't being treated filename of image. first non-keyword argument used internal name of image.

you must specify file keyword argument use file image:

img=photoimage(file="mat.png") 

also, depending on version have installed, tkinter may not support png files. if system not, above change you'll @ error tclerror: couldn't recognize image data. if case, you'll need convert image gif.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -