wxPythons CallLater 的访问冲突

发布于 2024-10-20 09:24:21 字数 859 浏览 3 评论 0原文

我正在尝试将一些代码从 Tkinter 转换为 wxPython。目前我正在尝试创建一个不断循环、更新时间的函数。但是,我遇到了一些问题。每当我关闭程序时,都会弹出一个窗口,并给出以下警告。

Access violation at address 1E058497 in module 'python26.dll'. Read of address 00000008.

这会导致我的 IDE (PyScripter) 冻结并崩溃。我认为它可能是在程序被破坏后尝试调用该函数。然后,这会导致它访问内存中不可用的位置,从而引发各种乐趣。任何帮助将不胜感激。

片段:

def tick (self):
    ''' Continually updates the time. '''

    TimeStr = '%I:%M %S %p'
    DateStr = '%A, %B %d, %Y'

    Time = time.strftime(TimeStr)
    Date = time.strftime(DateStr)

    self.TimeDate =  Time + '\t\t' + Date

    self.ST.SetLabel(self.TimeDate)

    wx.CallLater(1000, self.tick)

在 Tkinter 版本中 wx.CallLater(1000, self.tick) 被替换为 .after(1000, self.tick),如果有帮助的话。

编辑:

我在IDLE中尝试过,它似乎有效。然而,PyScripter 却没有那么幸运。

I'm attempting to convert some of my code from Tkinter to wxPython. Currently I'm trying to create a function that continually loops, updating the time. However, I have run into some problems. Whenever I close the program, a window pops up, and gives me the following warning.

Access violation at address 1E058497 in module 'python26.dll'. Read of address 00000008.

This then causes my IDE (PyScripter) to freeze and crash. I think it may be trying to call the function after the program has been destroyed. This then causes it to access an unavailable location in memory, causing all sorts of fun. Any help would be appreciated.

Snippet:

def tick (self):
    ''' Continually updates the time. '''

    TimeStr = '%I:%M %S %p'
    DateStr = '%A, %B %d, %Y'

    Time = time.strftime(TimeStr)
    Date = time.strftime(DateStr)

    self.TimeDate =  Time + '\t\t' + Date

    self.ST.SetLabel(self.TimeDate)

    wx.CallLater(1000, self.tick)

In the Tkinter version wx.CallLater(1000, self.tick) was substituted with .after(1000, self.tick), If that helps.

Edit:

I tried it in IDLE and it seemed to work. However, no luck in PyScripter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等待圉鍢 2024-10-27 09:24:21

你能做的是:

(1)
self.scheduled_call = wx.CallLater(1000, self.tick)

程序关闭时,通过 xxx.scheduled_call.??????() 取消
我忘记了该方法的确切名称,请查看 wx 文档。

或者,如果上述方法不可能

(2) 在实例中设置一个布尔变量来控制调用。
if self.var: wx.CallLater(1000, self.tick)

程序运行时 var 为 True
在程序关闭期间,将 xxx.var 设置为 False

what you can do is:

(1)
self.scheduled_call = wx.CallLater(1000, self.tick)

during program close, cancel via, xxx.scheduled_call.??????()
I forgot the exact name of the method, please check wx docs.

OR if the above is not possible

(2) set a boolean variable in the instance, that controls the call.
if self.var: wx.CallLater(1000, self.tick)

var is True when program is running
during program close, set xxx.var to False

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文