用TKinter如何实现实时数据更新功能?

我不明白 发布于 2018/11/05 17:16
阅读 510
收藏 0

目前我用Tkinter库做了一个GUI界面,主要功能是读取远程服务器的数据,然后显示在GUI界面上,间隔20或30秒读取一次远程数据,我采用多线程的方式来实现远程读取,这样GUI界面才会显示正常,不过这个多线程代码部分有问题。

这是我做的主界面,正常是点击“开始监控”按钮以后20-30秒以后界面的各项显示对应的数值。

 

#定义提取远程服务器数据的方法,SYSINFO.doAll()这个类函数是之前定义的提取远程服务器各项数据的,因为代码量有一些大
#我就不贴在上面了,但是提取完远程服务器数据以后,会保存在testdata这个列表中

def ReceiveData():
  global testdata
  testdata = SYSINFO.doAll()

#定义多线程的一个方法

def fun_timer():
  global timer,testdata
  testdata = SYSINFO.doAll()
  timer = threading.Timer(20, fun_timer)
  timer.start()

#定义开关按钮的状态全局变量

Button_Status = "OFF"

#定义“开始监控”按钮的方法

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()

#定义“关闭监控”

def Close_Monitor():
  global Button_Status
  Button_Status = "OFF"

 

目前运行这段代码以后,在多线程部分存在一些问题,好像是线程的逻辑有问题或者是如何让线程停止的条件有问题,运行以后即使testdata列表中有数据,GUI界面的这些“空”也不变化,mserver_window.update_idletasks() 这个方法不对吗?还是怎么的?

 
 
G
M
T
 
 
Detect languageAfrikaansAlbanianAmharicArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CorsicanCroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchFrisianGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHawaiianHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanKurdishKyrgyzLaoLatinLatvianLithuanianLuxembourgishMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPashtoPersianPolishPortuguesePunjabiRomanianRussianSamoanScots GaelicSerbianSesothoShonaSindhiSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshXhosaYiddishYorubaZulu
 
AfrikaansAlbanianAmharicArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CorsicanCroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchFrisianGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHawaiianHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanKurdishKyrgyzLaoLatinLatvianLithuanianLuxembourgishMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPashtoPersianPolishPortuguesePunjabiRomanianRussianSamoanScots GaelicSerbianSesothoShonaSindhiSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshXhosaYiddishYorubaZulu
 
 
 
 
 
 
 
 
 
Text-to-speech function is limited to 200 characters
 
 
Options : History : Feedback : Donate Close
加载中
当前问题已关闭评论
返回顶部
顶部