-1

I am making program in Python 2.7 using Tkinter and I want to create 3 sec intro. The intro is just canvas image that should show for 3 seconds and then be deleted. The problem is that my program is launching 3 seconds and then the code is done, so there is no intro. I read that it is because of output buffering. I don't know how to disable it, because everyone is talking about time.sleep and print function. That's my code:

 root = Tk()
 root.resizable(0,0)
 root.geometry('800x600+200+200')

 #canvas UI
 w = Tkinter.Canvas(root, bd=0, height=600, width=800)

 def intro():
     w.pack()
     intro = Tkinter.PhotoImage(file=r'intro.ppm')
     root.intro = intro
     w.create_image((0,0), image=intro, anchor='nw', tags=("intro"))
     time.sleep(3)
     w.delete("intro")

 intro()

 w.pack()

 root.mainloop ()
upgrade11
  • 57
  • 8

1 Answers1

1

You must not use time.sleep with Tkinter. When you want the program to pause, use after.

def intro():
    w.pack()
    intro = Tkinter.PhotoImage(file=r'intro.ppm')
    root.intro = intro
    w.create_image((0,0), image=intro, anchor='nw', tags=("intro"))
    w.after(3000, w.delete, "intro")
Rob Murray
  • 1,773
  • 6
  • 20
  • 32