在tkinter中连续调用Configure事件

编程入门 行业动态 更新时间:2024-10-24 16:21:05
本文介绍了在tkinter中连续调用Configure事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试编写一个函数来动态调整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( "<Configure>", connresiz)

我的问题是

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

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

2)更麻烦的是,当我拖动鼠标时,动态调整窗口大小会连续调用该函数!如何避免这种情况?

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

我考虑过要同时检查<Configure>和<ButtonRelease-1>事件是否存在,但是我不知道如何编码

I thought about checking at the simultaneous presence of a <Configure> and <ButtonRelease-1> events, but I dont 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.

由于窗口小部件的大小正在改变,因此在调整窗口大小时会连续调用它.这就是定义要执行的操作.尽管可以修改回调中的操作,但不能阻止它被调用.例如,您可以延迟调整图像的大小,直到一两秒钟都没有收到另一个<Configure>事件为止-这很可能意味着用户已停止交互式调整大小.

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.

更多推荐

在tkinter中连续调用Configure事件

本文发布于:2023-11-16 20:48:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607410.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事件   tkinter   Configure

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!