I'm making an intro sequence that displays an image with text underneath. the image is supposed to change when the button 'next' is pressed. When I press the button it gives me this error:
raceback (most recent call last):
File "C:\Users\Isaac\Desktop\code\lib\lib-tk\Tkinter.py", line 1470, in __call__
return self.func(*args)
File "C:\Users\Isaac\Desktop\code\Programs\Newlife (concept)\Newlife.py", line 15, in next
pic1=PhotoImage(file=img)
File "C:\Users\Isaac\Desktop\code\lib\lib-tk\Tkinter.py", line 3306, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Isaac\Desktop\code\lib\lib-tk\Tkinter.py", line 3262, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't open "pic3.gif": no such file or directory
Note; this happens after i press the button 3 times. I only want to have to press it once.
my code:
from Tkinter import *
Intro= [
"In the year 2164 Humanity killed itself.",
]
pic=0
def next():
global pic
pic+=1
img='pic'+str(pic)+'.gif'
pic1=PhotoImage(file=img)
image.create_image(0,0,image=pic1,anchor=NW)
intro_scene = Tk()
intro_scene.title('Destoyed')
text=Label(intro_scene,text=Intro[0],height=2)
image=Canvas(width=300,height=200)
Continue=Button(intro_scene,text='continue',bg='green',bd=3,width=10,command=next)
back=Button(intro_scene,text='back',bg='red',bd=3,width=5)
pic1=PhotoImage(file='pic1.gif')
image.create_image(0,0,image=pic1,anchor=NW)
image.pack(side='top'),text.pack(),back.pack(side='left'),Continue.pack(side='right')
intro_scene.mainloop()
I have checked that the whole next()
function is run like so:
def next():
global pic
print 'okay1'
pic+=1
print 'okay2'
img='pic'+str(pic)+'.gif'
print 'okay3'
pic1=PhotoImage(file=img)
print 'okay4'
image.create_image(0,0,image=pic1,anchor=NW)
print 'okay5'
Everything is printed.
My images are in GIF format and are named pic1, pic2, pic3, ect. The first image opens fine on startup.