How to realize the function of real-time data update with TKinter?

problem description

at present, I have made a GUI interface with the Tkinter library, the main function is to read the data from the remote server, and then display it on the GUI interface. I read the remote data every 20 or 30 seconds. I use multi-threading to achieve remote reading, so that the GUI interface will display normally, but there is something wrong with the multi-threaded code.

the environmental background of the problems and what methods you have tried


this is the main interface I made. Normally, the corresponding values are displayed in the interface 20-30 seconds after clicking the "start Monitoring" button.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

< H1 > defines the method to extract data from the remote server. The SYSINFO.doAll () class function is previously defined to extract the data from the remote server. Because there is a large amount of code, I will not post it, but after extracting the data from the remote server, it will be saved in the testdata list < / H1 >.

def ReceiveData ():

global testdata
testdata = SYSINFO.doAll()
< H1 > A method for defining multithreading < / H1 >

def fun_timer ():

global timer,testdata
testdata = SYSINFO.doAll()
timer = threading.Timer(20, fun_timer)
timer.start()
< H1 > define the state global variable of the switch button < / H1 >

Button_Status = "OFF"

< H1 > define the method of the start Monitoring button < / H1 >

def Start_Monitor ():

global Button_Status
if Button_Status == "OFF":
    Button_Status = "ON"
    timer = threading.Timer(1, fun_timer)
    timer.start()
    mserver_window.update_idletasks()
< H1 > define "turn off monitoring" < / H1 >

def Close_Monitor ():

global Button_Status
Button_Status = "OFF"

what result do you expect? What is the error message actually seen?

after running this code, there are some problems in the multi-threaded part, such as the logic of the thread or the condition of how to stop the thread. After running, even if there is data in the testdata list, the "empty" of the GUI interface will not change. Is mserver_window.update_idletasks () wrong? Or what?

Oct.21,2021

does not see how your interface program is written, the control needs to bind a IntVar or StrVar variable, and then modify the variable.

python3

from tkinter import *
import threading

class (Tk):
    def __init__(self):
        super().__init__()
        self.title('')
        self.int_n = IntVar()
        self.thelabel = Label(self, textvariable=self.int_n, padx=10, pady=20).pack()
        self.mythread = threading.Thread(target=self., name='_1')
        self.cond = threading.Condition() -sharp 
        self.stop = False
        self.mythread.start()
        self.bind('<Destroy>', self.)
        
    def (self):
        n=0
        while 1:
            with self.cond: -sharp 
                n = (n+1)%100
                self.int_n.set(n) -sharp 
                self.cond.wait(0.1) -sharp  20
                if self.stop: break  -sharp 

    def (self, event):
        with self.cond: -sharp 
            self.stop = True  -sharp 
            self.cond.notify()
            
if __name__ == '__main__':
     = ()
    .mainloop()
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b39c28-2c1c7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b39c28-2c1c7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?