Runnin a periodic task inside a GUI loop

607 Views Asked by At

i have a GUI running , showing some buttons.

top = Tkinter.Tk()
top.title('Interfaz')
B = Tkinter.Button(top, text ="name1", command = name1)
B.grid(row=0, column=0)
C = Tkinter.Button(top, text ="name 2", command = name 2)
C.grid(row=0, column=1)
D = Tkinter.Button(top, text ="name 3", command = name 3)
D.grid(row=0, column=2)
E = Tkinter.Button(top, text ="name 4", command = name 4)
E.grid(row=1, column=0)
F = Tkinter.Button(top, text ="name 5", command = name 5)
F.grid(row=1, column=1)
top.mainloop()

And what i want to do is just schedule a function inside the same py file to run every hour , so , i found this

Python periodic task inside an infinite loop

so i just added this line and it works

threading.Timer(3600, name1).start()

but what i would like to do is use this piece of code i adapted from another question i saw in this website.

scheduler = BlockingScheduler()
scheduler.add_job(name1, 'interval', minutes=50)
scheduler.start()

but if i put that inside the GUI loop , the GUI stops appearing and instead only the scheduler works.

1

There are 1 best solutions below

2
On

i just saw a solution so i'm going to leave it here .

I defined a function with the scheduler code

def tarea():
scheduler = BlockingScheduler()
scheduler.add_job(correoMinjus, 'interval', minutes=60)
scheduler.start()

then immediately after that i use thread like this.

thread.start_new_thread (tarea,())

And that's just what i wanted to do