I want one picture to be displayed in the canvas then the another to be displayed in the canvasafter 2 seconds.
i used time.speed(2) and canvas.delay(2000) but nothing works! Any help please?!

import ImageTk
import tkMessageBox
from Tkinter import*
from turtle import *
import time
root = Tk()#main window
canvas = Canvas(root, width=800, height=480, bg="white")#canvas named window
canvas.grid(column=1, rowspan=6, row=0, columnspan=5)
start=ImageTk.PhotoImage(file="start.gif")
after_prymase2a=ImageTk.PhotoImage(file="after_prymase2a.gif")
canvas.create_image(200,400,image=start)
canvas.create_image(100,100,image=after_prymase2a)
time.sleep(5)
root.mainloop()

something such as this:

def changepic():
    canvas.create_image(100,100,image=afterprymase2a)

canvas.after(2000, changepic)

time is in miliseconds though

thanks but why doesn't the sleep work...?

thanks but why doesn't the sleep work...?

If you look at the documentation for time.sleep(), you see that it basically blocks execution of that thread for the specified interval.
The problem is that GUI is a single thread,so if you block the thread then you block all execution in that thread.
This means that the GUI is unusable during the sleep and will in may cases lock up.

Most GUI toolkit has bulid in soultion for this.
In Tkinter it's after
Wxpython has wx.timer

You need to update the canvas as shown. Otherwise the Tkinter event loop just waits till time.sleep(5) is done.

import ImageTk
import tkMessageBox
from Tkinter import*
from turtle import *
import time

root = Tk() #main window

canvas = Canvas(root, width=800, height=480, bg="white")
canvas.grid(column=1, rowspan=6, row=0, columnspan=5)

start=ImageTk.PhotoImage(file="start.gif")
after_prymase2a=ImageTk.PhotoImage(file="after_prymase2a.gif")

canvas.create_image(200,400,image=start)
canvas.update()  # needed to do one pic at a time

time.sleep(5)

canvas.create_image(100,100,image=after_prymase2a)

root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.