使用Canvas Tkinter(OS X)的Python 2.7 time.sleep()
我正在用Tkinter用Python2.7编写程序,我想创建3秒的简介。介绍只是画布图像,应该显示3秒钟,然后删除。问题是,我的程序启动3秒钟,然后代码就完成了,所以没有介绍。我读到这是因为输出缓冲。我不知道如何禁用它,因为每个人都在谈论时间、睡眠和打印功能。这是我的密码:使用Canvas Tkinter(OS X)的Python 2.7 time.sleep(),python,macos,python-2.7,tkinter,tkinter-canvas,Python,Macos,Python 2.7,Tkinter,Tkinter Canvas,我正在用Tkinter用Python2.7编写程序,我想创建3秒的简介。介绍只是画布图像,应该显示3秒钟,然后删除。问题是,我的程序启动3秒钟,然后代码就完成了,所以没有介绍。我读到这是因为输出缓冲。我不知道如何禁用它,因为每个人都在谈论时间、睡眠和打印功能。这是我的密码: root = Tk() root.resizable(0,0) root.geometry('800x600+200+200') #canvas UI w = Tkinter.Canvas(root, bd=0,
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 ()
您不能将
time.sleep
与Tkinter一起使用。如果希望程序暂停,请使用
我想你的意思是
w.after(3000,w.delete,“intro”)
@tadhgmdonald-Jensen谢谢,编辑过的答案。
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")