之后应该调用什么小部件?

2024-04-19 09:13:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用after创建一个延迟回调。不过,我注意到许多不同的对象都有一个after方法,并且不清楚对tk.Frametk.Button调用after是否有任何区别

我没有看到任何一个指南提到无论调用什么对象after,您是否可以期望相同的行为。从实现来看,它似乎只是在一个公共的小部件基类中委托给self.tk.call('after', ms, name),但这并不意味着所有子类的行为都是相同的

如果我需要调用after时手头有多个小部件,有什么理由选择一个而不是另一个,或者我可以期望相同的行为吗


Tags: 对象方法nameself部件指南buttoncall
1条回答
网友
1楼 · 发布于 2024-04-19 09:13:11

I'm using after to create a delayed callback. I noticed though that many different objects have an after method, and it isn't clear if there's any difference between calling after on say a tk.Frame or a tk.Button.

不,没有区别。您可以使用任何想要的小部件调用after,它的行为将完全相同

Looking at the implementation, it seems like it just delegates to self.tk.call('after', ms, name) in a common base class of widgets, but that alone doesn't mean that the behavior will be identical for all subclasses.

事实上,的确如此。将其作为小部件上的方法调用是Tkinter实现的产物。在底层的tcl/tk库中,它只是一个没有绑定到任何小部件的函数调用

相关问题 更多 >