Python Pysimplegui,如何创建一个每10分钟从json url更新一次的活动窗口?
我环顾pysimplegui教程,复制一个活动窗口代码,并在通过url获取json文件时附加我自己的请求代码Python Pysimplegui,如何创建一个每10分钟从json url更新一次的活动窗口?,python,pysimplegui,Python,Pysimplegui,我环顾pysimplegui教程,复制一个活动窗口代码,并在通过url获取json文件时附加我自己的请求代码 # ---------------- Create Window ---------------- sg.ChangeLookAndFeel('Black') layout = [[sg.Text('')], [sg.Text('', size=(8, 4), font=('Helvetica', 20), justification='center', key=
# ---------------- Create Window ----------------
sg.ChangeLookAndFeel('Black')
layout = [[sg.Text('')],
[sg.Text('', size=(8, 4), font=('Helvetica', 20), justification='center', key='text')],
[sg.Text('', size=(8, 4), font=('Helvetica', 20), justification='center', key='test2')],
[sg.Exit(button_color=('white', 'firebrick4'), pad=((15, 0), 0))]]
window = sg.Window('Running Timer', layout, no_titlebar=True, auto_size_buttons=False, keep_on_top=True,
grab_anywhere=True)
# ---------------- main loop ----------------
while (True):
# --------- Read and update window --------
event, values = window.read(timeout=0)
# --------- Do Button Operations --------
if event is None or event == 'Exit':
break
response = requests.get('https://test.con/tracking.json')
# --------- Display timer in window --------
window['text'].update(response.json()[0]['code']+": "+str(response.json()[0]['nav']))
window['test2'].update(response.json()[1]['code'] + ": " + str(response.json()[1]['nav']))
count += 1
# Broke out of main loop. Close the window.
window.close()
这存在一个问题,即应用程序在循环中不断获取json文件。我希望每10分钟获取一次数据,我还需要第一次打开应用程序时获取的第一次数据。为什么不尝试将
timeout=0
更改为timeout=10*60*1000
(我猜超时时间以毫秒为单位,如果不是,请适当调整)。要在打开窗口之前获取数据,请尝试将window.read()
移动到递增的count
?为什么不尝试将timeout=0
更改为timeout=10*60*1000
(我猜超时时间以毫秒为单位,如果不是,请适当调整)。要在打开窗口之前获取数据,请尝试在递增计数后将window.read()
移动到?