1

试图让一个自我更新的车速表和时钟使用 gps 为我的卡车工作。到目前为止,我已经能够使用 easygui 和 msgbox 读取我想要的内容,但它不是自我更新,这对任何一个应用程序都没有多大帮助。下面是代码。任何帮助将不胜感激,我知道这很丑陋,可能不正确,但我是 python 新手。

import gps
from easygui import *
import sys
# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
while True:
     try:
          report = session.next()
          if report['class'] == 'TPV':
               if hasattr(report, 'time'):
                    hour = int(report.time[11:13])
                    hourfix = hour - 7
                    if hourfix < 12:
                         time = 'Current Time Is: ' + report.time[5:7] + '/' + report.time[8:10] + '/' + report.time[0:4] + ' ' + str(hourfix) + report.time[13:19] + ' am'
                    else:
                         hourfix = hourfix - 12
                         time =  'Current Time Is: ' + report.time[5:7] + '/' + report.time[8:10] + '/' + report.time[0:4] + ' ' + str(hourfix) + report.time[13:19] + ' pm'
          if report['class'] == 'TPV':
               if hasattr(report, 'speed'):
                    speed = int(report.speed * gps.MPS_TO_MPH)
                    strspeed = str(speed)
                    currentspeed = 'Current Speed Is: ' + strspeed + ' MPH'
                    msgbox(time + "\n" + currentspeed, "SPEEDO by Jono")
     except KeyError:
          pass
     except KeyboardInterrupt:
          quit()
     except StopIteration:
          session = None
          print "GPSD has terminated"
4

0 回答 0