tkinter tkMessageBox not working in thread

前端 未结 3 679
遥遥无期
遥遥无期 2021-01-22 08:08

i have tkinter class and some functions in it, (assume all other functions are present to initiate the GUI). what i have done i have started one self.function as a thread from o

3条回答
  •  悲&欢浪女
    2021-01-22 08:49

    If you want your other thread to block until you get response (e,g: you want to ask a question and wait for the answer) you can use this function:

    def runInGuiThreadAndReturnValue(self, fun, *args, **kwargs):
        def runInGui(fun, ret, args, kwargs):
            ret.append(fun( *args, **kwargs))
        ret = []
        sleeptime = kwargs.pop('sleeptime', 0.5)
        self.after(0, runInGui, fun, ret, args, kwargs)
        while not ret:
            time.sleep(sleeptime)
        return ret[0]
    

提交回复
热议问题