我有以下代码,它应该打开一个弹出窗口。现在,如果用户在弹出窗口中单击“是”,它应该显示主程序窗口,否则退出:
import tkMessageBox
from Tkinter import *
root = Tk()
root.withdraw() # hide the main program window
if not tkMessageBox.askyesno("Title",
"Do you want to start the program now?"):
# If the user pressed the 'No' botton
root.destroy()
exit(0)
print "test"
text = Text(root)
text.insert(INSERT, "Hello")
text.pack()
root.deiconify() # show the main program window
root.mainloop()
当我运行它并单击弹出窗口中的“是”按钮时,我看到“测试”已输出到终端,但弹出窗口冻结并且我看不到带有文本元素的主程序窗口。我看过Tkinter TkMessageBox 在单击 OK 后没有关闭,但这对我没有帮助。有人有解决这个问题的方法吗?