为什么“几何()"方法有延迟吗?

编程入门 行业动态 更新时间:2024-10-23 09:30:57
本文介绍了为什么“几何()"方法有延迟吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

如果我运行这个 Python 代码:

from Tkinter import *;w = Tk();w.geometry("640x480");打印( w.geometry() )

我会得到1x1+0+0"的输出.但是,如果我启动解释器并将其作为两个单独的执行命令,我会得到完全不同的输出:

<预><代码>>>>从 Tkinter 进口 *;w = Tk();w.geometry("640x480")''>>>w.geometry()'640x480+101+73'

似乎几何图形不是立即应用的,还需要其他东西:(.也许有人知道我需要做什么才能更新几何图形到位?我需要它来正确居中/定位主窗口和子窗口.

解决方案

在窗口(或小部件)上调用 update_idletasks() 将强制更新其几何图形.

这是来自 Tkinter 参考的一小段文本:

<块引用>

在应用程序更新其空闲任务之前,几何图形是不准确的.特别是,所有几何图形最初都是1x1+0+0",直到小部件和几何图形管理器协商好它们的位置.

If i run this Python code:

from Tkinter import *; w = Tk(); w.geometry( "640x480" ); print( w.geometry() )

i will get "1x1+0+0" output. But if i start interpreter and execute this as two separate commands, i will get completely different output:

>>> from Tkinter import *; w = Tk(); w.geometry( "640x480" ) 
'' 
>>> w.geometry() 
'640x480+101+73'

It seems geometry is not applied instantly, something else is needed : (. Maybe anyone knows what i need to do in order to update geometry inplace? I need it to correctly center/position main and child windows.

解决方案

Calling update_idletasks() on a window (or a widget) will force its geometry to update.

Here's a little text snippet from the Tkinter reference:

The geometry is not accurate until the application has updated its idle tasks. In particular, all geometries are initially "1x1+0+0" until the widgets and the geometry manager have negotiated their positions.

这篇关于为什么“几何()"方法有延迟吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

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

发布评论

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

>www.elefans.com

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