是Tkinter winfo_reqwidth"总是最新的"?

时间:2016-01-24 15:37:09

标签: python tkinter

来自文档:

w.winfo_width()

Returns the current width of w in pixels. See the remarks on geometry
updating under .winfo_geometry(), above. You may prefer to use the
.winfo_reqwidth() method, described above; it is always up to date.

不是根据我的经验。每次单击标签后,以下程序将打印相同值两次。该值逐行变化。

from Tkinter import *

root = Tk()
t = "a label"
padx = 0
f = Frame(root, padx=padx, bg='red')
l = Label(f, text=t, bg='yellow')
def cb(e):
    global t, padx
    w = f.winfo_reqwidth()
    print w,
    t = t + 'x'
    padx += 10
    f.configure(padx=padx)
    l.configure(text=t)
    #f.update_idletasks()
    w = f.winfo_reqwidth()
    print w
f.place(x=0,y=0)
l.pack()
l.bind('<Button-1>', cb)
mainloop()

打印:

49 49
76 76
103 103

取消注释f.update_idletasks行并打印:

49 76
76 103
103 130

文档错了吗?我读错了吗?有没有办法在更改后立即检索小部件所需的宽度和高度?

0 个答案:

没有答案