python RuntimeError: threads can only be started once 질문드립니다.

조회수 915회

안녕하세요 얼마전에 python UI 관련 질문글을 올렸었는데

멀티 쓰레드 기능등을 활용해보라는 조언이 있어

나름 열심히 구글링을 해서 원하는 결과값이 나오게 되었는데요

문제가 UI실행 후 값을 입력하고 매칭 버튼을 누를 경우

값이 같으면 녹색 다를경우 빨간색으로 백그라운드 색이 변경 후

5초 후에 다시 흰색 배경으로 돌아오는데

문제가 한번만 해당 동작을 수행하고 한번더 매칭 버튼을 누를경우

RuntimeError: threads can only be started once 에러가 발생하며 동작이 되지 않습니다.

쓰레드에 대해 이해를 못해 발생된 문제 인거 같은데

어떻게하면 매칭 버튼 후 녹색 혹은 빨간색으로 변경 후5초후에 흰색으로 배경색이 돌아오는 작업을

지속 반복할 수 있을지 도움요청 드립니다.

감사합니다.

from tkinter import *

import threading,time



def test1():    

    time.sleep(5)

    window.configure(bg="white")

    l1.configure(bg="white", fg="black")

    l2.configure(bg="white", fg="black")  



def test2():

    time.sleep(5)

    window.configure(bg="white")

    l1.configure(bg="white", fg="black")

    l2.configure(bg="white", fg="black")   




t1=threading.Thread(target=test1)

t2=threading.Thread(target=test2)




def process1():

   com = str(e1.get())

   com1 = str(e2.get())  

   if com == com1:

      window.configure(bg="green")

      l1.configure(bg="green", fg="white")

      l2.configure(bg="green", fg="white")   

      t1.start()



   else:

      window.configure(bg="red")

      l1.configure(bg="red", fg="white")

      l2.configure(bg="red", fg="white")

      t2.start()




window = Tk()

window.title("Monitoring System")

window.geometry("500x300+100+100")

window.configure(bg='white')

window.resizable(False,False)

l1 = Label(window, text="MES", font="helvetica 16 italic",bg="white", fg="Black") 

l2 = Label(window, text="BARCODE", font="helvetica 16 italic",bg="white", fg="Black") 

l1.grid(row=1, column=0)

l2.grid(row=2, column=0)

e1 = Entry(window, font=12, bg="white", fg="Black") 

e2 = Entry(window, font=12, bg="white", fg="Black")

e1.grid(row=1, column=1)

e2.grid(row=2, column=1)



b1 = Button(window,text="MATCHING", font="helvetica 12 italic",bg="white", command=process1)

b1.grid(row=3, column=0)

l1.place(x=50, y=50)

e1.place(x=50, y=90, width=180, height=40)

l2.place(x=270, y=50)

e2.place(x=270, y=90, width=180, height=40)

b1.place(x=200, y=190)

window.mainloop()

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)