Home > Enterprise >  Is there a way to take a break after reading a row and then go back and read the next row and repeat
Is there a way to take a break after reading a row and then go back and read the next row and repeat

Time:07-27

looking to do the same thing but with a break in the below code after each row:

for i in file:
   x1.config(text=i[1])
   x2.config(text=i[2]) 
   x3.config(text=i[3])

label1 = ttk.Label(root,text="")
label1.place(x=680,y=185)

label2=ttk.Label(root,text="")
label2.place(x=680,y=210)

label3=ttk.Label(root,text="")
label3.place(x=680,y=235)

data in file is: enter image description here

output is:

enter image description here

desired output should be same but with 1 sec break after each row.

CodePudding user response:

You can halt a running program temporarily using the sleep function from the built in time module. E.g.

from time import sleep

for line in file:
    print(line)
    sleep(1)  # in seconds

CodePudding user response:

Can be solved using an iterator type of function. you can call the below function in the delay range and it will give you a new line on every call.

def file_gen(f_name):
    with open(f_name) as f:
        for line in f:
            yield line
  • Related