[英]Why does update_idletasks() interfere with overrideredirect() functionality?
I have a top-level window, whose specific location is set via geometry string.我有一个顶级窗口,它的具体位置是通过几何字符串设置的。
w.overrideredirect(True)
is called because the top-level window mustn't have any window manager decorations. w.overrideredirect(True)
被调用是因为顶级窗口不能有任何窗口管理器装饰。 The official documentation states:官方文档指出:
Be sure to call the .update_idletasks() method (see Section 26, “Universal widget methods”(p. 97)) before setting this flag.
在设置此标志之前,请务必调用 .update_idletasks() 方法(请参阅第 26 节“通用小部件方法”(第 97 页))。
So that's exactly what I did, but now window manager decorations appear.所以这正是我所做的,但现在出现了窗口管理器装饰。 It works fine if I don't call
w.update_idletasks()
.如果我不调用
w.update_idletasks()
它工作正常。
Code:代码:
w = tk.Toplevel(self.parent_frame)
w.geometry('48x240+1567+209')
w.update_idletasks()
w.overrideredirect(True)
I'm using Python 3.8.10 with Tk version 8.6.10 on Ubuntu 20.04.3 LTS.我在 Ubuntu 20.04.3 LTS 上使用 Python 3.8.10 和 Tk 版本 8.6.10。
That's not official documentation, and it is wrong.那不是官方文档,而且是错误的。 The exact opposite is true: you must set the flag before tkinter has the chance to draw the window on the screen.
恰恰相反:您必须在tkinter 有机会在屏幕上绘制窗口之前设置标志。 That means before
mainloop
is started, and before any calls to update
or update_idletasks
.这意味着在
mainloop
启动之前,以及对update
或update_idletasks
任何调用之前。
The reasoning is simple: setting the overrideredirect
merely sets a flag.原因很简单:设置
overrideredirect
只是设置一个标志。 When the window is rendered, tkinter will look to see if the flag is set and then draw the window.渲染窗口时,tkinter 将查看是否设置了标志,然后绘制窗口。 If the flag is not set, a border is added to the window.
如果未设置标志,则会向窗口添加边框。
Setting the flag after the window has already been drawn will have no effect since the border will already have been drawn.在绘制窗口之后设置标志将不起作用,因为边框已经绘制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.