I want to create two times in one tkinter window using multiprocessing. I want to run two timers simultaneously. Here is the code. First it shows the window with the given text and then it shows error.
Code:
from multiprocessing import Process
from time import time, sleep
from tkinter import *
class Main:
def __init__(self):
self.root = Tk()
self.root.geometry('300x300')
self.lab1 = Label(self.root, text='None')
self.lab1.place(x=10, y=10)
self.lab2 = Label(self.root, text='None')
self.lab2.place(x=10, y=50)
self.root.mainloop()
def c1(self):
st = time()
for _ in range(10):
self.lab1['text'] = int(time()-st)
self.root.update()
sleep(1)
def c2(self):
st = time()
for _ in range(10):
self.lab2['text'] = int(time()-st)
self.root.update()
sleep(1)
def main(self):
self.p1 = Process(target=self.c1)
self.p2 = Process(target=self.c2)
self.p1.start()
self.p2.start()
self.p1.join()
self.p2.join()
if __name__ == '__main__':
start = Main()
start.main()