gpt4 book ai didi

python - 如何偶尔刷新一次Python脚本?

转载 作者:行者123 更新时间:2023-12-01 06:08:30 25 4
gpt4 key购买 nike

所以我创建了一个类,其中包含使用 wxPython 的 GUI。你如何让它每分钟刷新一次?

最佳答案

对于间隔发生的事情,请使用 Timer 。来自 WxPyWiki :

def on_timer(event):
pass # do whatever

TIMER_ID = 100 # pick a number
timer = wx.Timer(panel, TIMER_ID) # message will be sent to the panel
timer.Start(100) # x100 milliseconds
wx.EVT_TIMER(panel, TIMER_ID, on_timer) # call the on_timer function

For some reason, this code didn't work when I tried it. The reason was the timer had to be a class member. If you put that code into the init() method and add self. before timer, it should work. If it doesn't, try making on_timer() a class member too. -- PabloAntonio

<小时/>

I've had problems closing my frame, when there was a Timer running.

Here's how I handled it:

def on_close(event):
timer.Stop()
frame.Destroy()

wx.EVT_CLOSE(frame, on_close)

关于python - 如何偶尔刷新一次Python脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6923875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com