I am trying to create a program that reads lines from a file and puts them into a tkinter window. At the moment my code is this:
def read_notifications():
#def update():
# window.config(text=str(random.random()))
# window.after(1000, update)
aaa = 1
while True:
re = open("Y:/System Info/notifications.txt", "r")
rf = re.read()
rh = rf.count("\n")
re.close()
lines = [line.rstrip('\n') for line in open("Y:/System Info/notifications.txt")]
rk = -1
while True:
aaa = aaa + 2
rk = rk + 1
#print(lines[rk])
rl = rk + 1
ya = lines[rk].split("#")
yb = str(tomrt)
if ya[1] == yb:
yc = "Tommorow"
else:
if ya[1] == "0":
yc = "Monday"
if ya[1] == "1":
yc = "Tuesday"
if ya[1] == "2":
yc = "Wednesday"
if ya[1] == "3":
yc = "Thursday"
if ya[1] == "4":
yc = "Friday"
if ya[1] == "5":
yc = "Saturday"
if ya[1] == "6":
yc = "Sunday"
c = 650
window = tk.Tk()
#back = tk.Frame(width=700, height=c)
#back.pack()
window.title("Notifications")
window.iconbitmap("1235.ico")
#Subject
lbl = tk.Label(window, text=ya[0])
lbl.config(font=("Courier", 18))
lbl.grid(column=0, row=0)
#lbl.pack(side=tk.LEFT,)
#Day
lbl = tk.Label(window, text=" " + yc)
lbl.config(font=("Courier", 16))
lbl.grid(column=2, row=0)
#Type
lbl = tk.Label(window, text=ya[2])
lbl.config(font=("Courier", 16))
lbl.grid(column=4, row=0)
#Descripion
lbl = tk.Label(window, text=ya[4])
lbl.config(font=("Courier", 16))
lbl.grid(column=6, row=0)
#lbl.pack(side=tk.LEFT)
#window.after(1000, update)
if rl == rh:
print("hello")
break
if aaa > 2:
time.sleep(4)
window.destroy()
else:
window.mainloop()
I am not sure why this doesn't work properly. I am trying to make it so the tkinter window will update itself every 4 seconds, as another program is making changes to the notifications.txt file and I want the tkinter windows to update accordingly.
Aucun commentaire:
Enregistrer un commentaire