Intermittent Python thread error, “main thread is not in main loop”

前端 未结 2 577
后悔当初
后悔当初 2021-01-13 01:01

Middle aged dad (electrical engineer not programmer by trade) trying to teach my 13 year old daughter electronics and programming. So far, I love Python. I am building a pro

2条回答
  •  囚心锁ツ
    2021-01-13 01:43

    GUI toolkits are not threadsafe. You can only built and change your GUI from the main thread. Since reading the temperature does not take that long, you can remove all the threading code and use the after-method from Tk.

    Your read_temp_raw function is very complicated:

    def read_temp_raw():
        with open(device_file) as temp:
            return temp.read().split('\n')
    

提交回复
热议问题