私はずっと前にこれをやろうとしました。これは美しい方法ではないことを私は知っています。おそらくPythonは、このようにすることで私を大いに嫌っていますが、それでも私にとってはうまくいきました。
それでもエラー メッセージが表示されますが、機能します。おそらく他の誰かが私を修正して、より良い方法でそれを作ることができます. コードは次のとおりです。
import Tkinter
import tkMessageBox
import thread
top = Tkinter.Tk()
def hello():
tkMessageBox.showinfo("Say Hello", "Hello World")
B1 = Tkinter.Button(top, text = "Say Hello", command = hello)
B1.pack()
thread_to_stop = thread
try:
thread_to_stop.start_new_thread(top.mainloop,(0,))
except:
pass
print "Python doesn't like this very much"
raw_input("You choose when to close it!")
# Do more stuff here....
top.destroy()