python + tkinter error

Error one: do not display pictures

photo = PhotoImage(file='E:\\bg2.gif')
lbi = Label(windows, image = photo)
lbi.grid(row=0, columnspan = 2)

Solution:

Plus global 

global photo
photo = PhotoImage(file='E:\\bg2.gif')
lbi = Label(windows, image = photo)
lbi.grid(row=0, columnspan = 2)

错误二:_tkinter.TclError: image "pyimage1" doesn't exist 

Only one root window can exist in a program, that is to say, only one Tk () can exist, and other windows can only exist in the form of top-level windows (Toplevel ())

Solution:

Change Tk () to Toplevel ()

 
Published 128 original articles · Like 132 · Visits 170,000+

Guess you like

Origin blog.csdn.net/yql_617540298/article/details/104340913