繁体   English   中英

有没有办法在窗口打开后立即在 tkinter 中调用函数?

[英]Is there a way to call a function in tkinter as soon as the Window is opened?

我是 tkinter 的新手,希望能帮到你。 我在 Windows 机器上。

这是我的意思的一个例子:

from tkinter import *    
def test():
    print("Window opened!")
root = Tk()
text = Text(root)
text.insert(INSERT, "FOO BAR")
text.pack()
root.mainloop(execute function)

我认为这可以满足您的要求。 它使用通用小部件after_idle()方法,因此在窗口显示之前不会调用该函数。

from tkinter import *

def test():
    print("Window opened!")
root = Tk()
text = Text(root)
text.insert(INSERT, "FOO BAR")
text.pack()
root.after_idle(test)  # Call test() next time system is idle.
root.mainloop()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM