问题描述
如果我运行这个 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 separatecommands, 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 geometryinplace? 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:
这篇关于为什么“几何()"方法有延迟吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!