<Configure> 的连续调用tkinter 中的事件 [英] Continuous calls of the <Configure> event in tkinter

查看:35
本文介绍了<Configure> 的连续调用tkinter 中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个函数来动态调整 tkinter 窗口中显示的图像的大小.因此我将此函数绑定到 Configure 事件:

I am trying to write a function to dynamically resize an image displayed in a tkinter window. Therefore I bound this function to the Configure event:

connroot.bind( "", connresiz)

我的问题是:

  1. connresiz() 函数在程序启动时被调用 3 次(为什么是 3 次?),并且

  1. That the connresiz() function gets called 3 times (why 3?) at program start, and

比较麻烦,就是动态调整窗口大小,在我拖动鼠标时不断调用函数!如何避免这种情况?

More troublesome, that dynamically resizing the window calls the function continuously as I drag the mouse! How can avoid this?

我想检查同时存在 事件,但我不知道如何编码.

I thought about checking at the simultaneous presence of a <Configure> and <ButtonRelease-1> events, but I don't know how to code it.

推荐答案

根据官方 tk 文档,<Configure> 事件会在每当其大小、位置或边框宽度发生变化时触发,并且有时当它在堆叠顺序中改变位置时."这在启动过程中可能会发生多次.

According to the official tk documentation, <Configure> events fire "whenever its size, position, or border width changes, and sometimes when it has changed position in the stacking order." This can happen several times during startup.

当您调整窗口大小时,它会被连续调用,因为小部件的大小正在发生变化.这就是它的定义.你不能阻止它被调用,但你当然可以修改你在回调中所做的事情.例如,您可以延迟调整图像大小,直到在一两秒内没有收到另一个 事件——这可能意味着用户已停止交互式调整大小.

It is called continuously while you resize the window because the size of the widget is changing. That's what it's defined to do. You can't prevent it from being called, though you can certainly modify what you do in the callback. For example, you could delay resizing the image until you've not received another <Configure> event for a second or two -- which likely means the user has stopped interactive resizing.

这篇关于&lt;Configure&gt; 的连续调用tkinter 中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆