嘿,我想要的是同一张图片在不同位置弹出4秒。此时,所有照片立即弹出。我试图将time.sleep添加到for循环中,但是所有照片立即以任何方式弹出。请尝试我的代码,并通过虚拟方式向我展示如何修复,因为我是python的新手。谢谢
from tkinter import *
from PIL import ImageTk, Image
from os import walk, getenv, system
from shutil import copyfile
import subprocess
import requests, subprocess, os, tempfile
import os
import tkinter.messagebox
import time
# This is the fuction that makes the original photo and is what root.after calls to later on in the code.
def ShowAnotherWin(i):
win = Toplevel()
image = ImageTk.PhotoImage(Image.open('C:/Users/capture.PNG'))
win.geometry(i)
canvas =Canvas(win, width=420, height=560)
canvas.create_image(0, 0, image= image, anchor=NW)
canvas.pack()
win.overrideredirect(1)
win.mainloop()
# This is the list it, it consists of different y and x interpects point and will be combined with the showanotherwin to makee a unique image pop up.
YourImageList = ['420x544+0+0',
time.sleep(1)
'420x544+200+600',
time.sleep(88)
'420x544+1300+100',
'420x544+1500+800',
'420x544+900+500',
'420x544+500+75',
]
# this code right here takes all the elements in the list and combines it with the showanotherwin. It then displays on screen.
root = Tk()
for i in YourImageList:
root.after(0, lambda i=i: ShowAnotherWin(i))
# time.sleep(1)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> leads to all the photos poping up with the only, effect being the duration of the photos poping up. Please help!!
# this right here is just making another photo by itself dont worry about it.
image = ImageTk.PhotoImage(Image.open('C:/Users/capture.PNG'))
root.geometry('420x544+750+200')
canvas = Canvas(root, width=420, height=560)
canvas.create_image(0, 0, image= image, anchor=NW)
canvas.pack()
root.overrideredirect(1)
root.mainloop()
答案 0 :(得分:0)
您基本上将它们全部武装起来,在这里root.after( 0 ,...
延迟0毫秒后出现。
for i in YourImageList:
root.after(0, lambda i=i: ShowAnotherWin(i))
答案 1 :(得分:0)
简单的方法是:
@ViewChild('firstTable') myTable: DatatableComponent;
另一种方法是在for i, x in enumerate(YourImageList):
root.after(i*4000, lambda x=x: ShowAnotherWin(x))
内部调用after()
:
ShowAnotherWin()