I'm having trouble with a function that shows an image for two seconds on screen, and then is destroyed. When the program runs the functions initial call procedurely works fine, but if the function is then called via a button built in tkinter I get an error.
appcwd = os.getcwd()
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
size = str(screensize[0])+'x'+str(screensize[1])
def wlcm_scrn(event=None):
def destroy_wlcm(event=None):
wlcm_scrn.destroy()
global appcwd
global screensize
wlcm_scrn = tkinter.Tk()
file=appcwd+"\\Run_Files\\splash.gif"
splsh_img = tkinter.PhotoImage(file=file)
splosh = tkinter.Label(wlcm_scrn,image=splsh_img)
wlcmh = splsh_img.height()/2
wlcmw = splsh_img.width()/2
splosh.pack()
wlcm_scrn.config(bg='black')
wlcm_scrn.overrideredirect(True)
wlcm_scrn.bind("<Escape>",destroy_wlcm)
wlxym = '+'+str(int((screensize[0]/2)-wlcmw))+'+'+str(int((screensize[1]/2)-wlcmh))
wlcm_scrn.geometry(wlxym)
wlcm_scrn.wm_attributes("-topmost", 1)
wlcm_scrn.after(2000,destroy_wlcm)
wlcm_scrn.mainloop()
wlcm_scrn() #Call through procedure.
Button that calls the function.
view_img = tkinter.Button(cfrm,text='Show splash image',command=wlcm_scrn)
Error message when called through button command.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "C:\Python33\POS_Solution\Rattle_Hum_POS.py", line 1755, in run_wlcm_scrn
wlcm_scrn()
File "C:\Python33\POS_Solution\Rattle_Hum_POS.py", line 34, in wlcm_scrn
splosh = tkinter.Label(wlcm_scrn,image=splsh_img)
File "C:\Python33\lib\tkinter\__init__.py", line 2596, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Python33\lib\tkinter\__init__.py", line 2075, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage3" doesn't exist
What is "pyimage3" and why doesn't it exist? Any help would be apprecaited. Thanks.