我有以下脚本,它将海拔数据从 gpsd 模块输出到控制台并保持最新。我想在 tkinter 界面中显示相同的数据,但无论我尝试过什么,我似乎都无法像控制台那样刷新数据。它输出初始数据正常,但没有给我最新数据。我是一个新手,所以也许我在做一些愚蠢的事情。
我已经附加了刚刚输出到控制台的初始代码,因为它是我所基于的。
谢谢,丹。
import os
from gps import *
from time import *
import time
import threading
gpsd = None #seting the global variable
os.system('clear') #clear the terminal (optional)
class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
global gpsd #bring it in scope
gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
self.current_value = None
self.running = True #setting the thread running to true
def run(self):
global gpsd
while gpsp.running:
gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
if __name__ == '__main__':
gpsp = GpsPoller() # create the thread
try:
gpsp.start() # start it up
while True:
os.system('clear')
print 'altitude (m)' , gpsd.fix.altitude
time.sleep(5) #set to whatever
except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
print "\nKilling Thread..."
gpsp.running = False
gpsp.join() # wait for the thread to finish what it's doing
print "Done.\nExiting."