【发布时间】:2018-08-21 04:06:59
【问题描述】:
我有一个带有按钮的窗口,我希望该按钮创建一个带有新按钮的新窗口。新按钮将破坏新窗口,因此代码应该继续并打印“hi”。
from tkinter import *
root1 = Tk()
def create():
root2 = Tk()
Button(root2,
text="2",
command=lambda: root2.destroy()).grid()
root2.mainloop()
print("hi")
Button(root1,
text="1",
command=lambda: create()).grid()
root1.mainloop()
我发现 root2 的创建和销毁都很好,但是“print(“hi”)”行仅在 root1 关闭后运行。我希望在单击显示“2”的按钮后立即执行“print("hi") 行。任何想法将不胜感激。非常感谢!
【问题讨论】:
标签: python python-3.x tkinter