1. 程式人生 > >GUI和多執行緒

GUI和多執行緒

GUI和多執行緒

為了能夠讓分離的執行緒資訊交流,我不得不使用Inter-Process-Communication(IPC),這是一種高階的用法。

Mutiple threads執行在相同的計算機儲存空間,所以沒必要使用IPC,IPC會增加我們的程式碼的複雜性。

使用執行緒,匯入執行緒

from threading import Thread

oop = OOP()

runT= Thread(target = oop.methodInAThread)
oop.win.mainloop()

開始一個執行緒

新增自己的方法,然後呼叫方法通過回撥函式,呼叫自己的方法,callback function。

def createThread(self):
	runT = Thread(target=self.methodInAThread)
	runT.start()
def clickMe(self):
	self.action.configure(text='Hello ' + self.name.get())
	self.createThread()