'<Configure>' 的奇怪行为打回来 [英] odd behavior with '<Configure>' callback

查看:23
本文介绍了'<Configure>' 的奇怪行为打回来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我 bind() 一个回调时,我遇到了一些奇怪的行为在我用来包含图像的标签上 我想调整其包含 Toplevel 的大小.

I'm experiencing some odd behavior when I bind() a callback to <Configure> on a Label I'm using to contain an image I want to resize as its containing Toplevel is resized.

根据文档, 回调应该在用户调整窗口大小时被调用(即顶层).我发现回调是在没有用户交互的情况下被调用.事实上,它似乎是当我更新图像时被调用 from 处理程序对调整大小的响应,这会导致烦人的循环当用户移动(!)窗口时结束.每个电话都有event.width 和/或 event.height 稍大或稍小,取决于我如何调整图像大小.这几乎就像我为设置新图像所做的调用(Label.configure(image={newImage})) 正在触发回调,但这毫无意义.

According to the documentation, the <Configure> callback is supposed to get called when the user resizes the window (i.e. the Toplevel). What I'm finding is that the callback is getting called with no user interaction. In fact, it seems to be getting called when I update the image from the handler in response to the resize, which leads to an annoying loop which ends when the user moves (!) the window. Every call has event.width and/or event.height slightly larger or smaller, depending on how I've resized the image. It's almost as though the call I make to set the new image (Label.configure(image={newImage})) was triggering the callback, but this makes no sense.

我试过用 pdb 跟踪这个,但我发现的只是一个电话来了来自 Tkinter.Tk.mainloop() 没有说明是什么导致了它.我也试过用一个小演示来复制这个程序(我可以包括在这里),但不能,所以我希望有人可能至少能够回答这个问题:

I've tried tracing this with pdb, but all I find is a call coming from Tkinter.Tk.mainloop() with no indication of what led to it. I've also tried to duplicate this with a small demo program (which I could include here), but cannot, so I'm hoping someone might at least be able to answer the question:

除了用户交互(或我自己的任何显式调用)代码),什么会导致 回调被调用?

Apart from user interaction (or any explicit call in my own code), what could cause a <Configure> callback to be called?

谢谢.

推荐答案

每当小部件的大小发生变化时,` 事件就会被触发.它不限于交互式调整大小.如果您的绑定更改了小部件的大小,则会再次生成该事件.

The ` event is fired whenever the size of the widget changes. It isn't restricted to interactive resizing. If your binding changes the size of the widget, the event will be generated again.

根据官方tcl/tk文档:

一个配置事件被发送到一个窗口大小时,位置或边框宽度发生变化,有时发生变化时在堆叠顺序中的位置.

A Configure event is sent to a window whenever its size, position, or border width changes, and sometimes when it has changed position in the stacking order.

这篇关于'&lt;Configure&gt;' 的奇怪行为打回来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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