Tkinterのmainloopでループ用スレッドを挿入

3723 ワード

import Thread

class Product():
    def __init__(self):
        pass

    def f1(self):
         while True:
             time.sleep(1)
             print(1)

    def f2(self):
         while True:
             time.sleep(2)
             print(2)

    def listen(self):                           #    join(),     mainloop,Tkinter   。
          t = Thread(target=self.f1)
          t2 = Thread(target=self.f2)
          t.start()
          t2.start()


if __name__ == "__main__":
    window = tk.Tk()
    p = Product(window)
    p.listen()            
    window.mainloop()