简体   繁体   English

wxPython等效于Tkinter .after()

[英]wxPython Equivalent to Tkinter .after()

Is there an equivalent to Tkinter's .after() in wxPython? 在wxPython中有与Tkinter的.after()等效的东西吗?

For those that don't know .after() allows the running of functions at some point in the future. 对于那些不知道的人, .after()允许将来某个时候运行功能。 This can be used to make loops with functions. 这可用于使函数循环。

I'm attempting to make a clock, so this would be handy for making it tick. 我正在尝试制造一个时钟,因此可以使其打勾。

To answer your specific question, you can use wx.CallAfter and wx.CallLater . 要回答您的特定问题,可以使用wx.CallAfterwx.CallLater The former is roughly equivalent to tkinter's after_idle command, and the latter is the same as after (ie: it takes a number of milliseconds to wait as an argument) 前者与after_idleafter_idle命令大致等效,后者与after相同(即:等待参数需要花费毫秒数)

As a third option you can use wx.Timer , upon which wx.CallLater is based. 作为第三个选项,您可以使用wx.Timer ,它是wx.CallLater的基础。 This gives you more control over the scheduled jobs, allowing you to cancel or restart them (similar to what you can do with tkinter's after_cancel ) 这使您可以更好地控制计划的作业,从而可以取消或重新启动它们(类似于使用after_cancelafter_cancel

There are several functions in wx.Python to do that. wx.Python中有几个函数可以做到这一点。 You should check the "Process and events" section of the wxPython demos, More especifically those related with wx.Timer 您应该检查wxPython演示的“流程和事件”部分,更具体地说,是与wx.Timer相关的那些

The wx.Timer class allows you to execute code at specified intervals from within the wxPython event loop. wx.Timer类允许您从wxPython事件循环内以指定的间隔执行代码。 Timers can be one-shot or repeating. 计时器可以是单拍或重复。 This demo shows the principle method of using a timer (with events) as well as the convenient wx.FutureCall class. 该演示演示了使用计时器(带有事件)的原理方法以及方便的wx.FutureCall类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM