あなたがはい/いいえ]または[OK /ボタンをキャンセルしていないダイアログを使用する必要がある、とあなたがの戻り値をキャプチャする必要がありますユーザーが何をクリックしたかを知るダイアログ。これから、ファイルに書き込むかどうかを決めることができます。例えば
:
import Tkinter as tk
import tkMessageBox
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.button = tk.Button(self, text="Push me", command=self.OnButton)
self.button.pack()
def OnButton(self):
result = tkMessageBox.askokcancel(title="File already exists",
message="File already exists. Overwrite?")
if result is True:
print "User clicked Ok"
else:
print "User clicked Cancel"
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
effbot.orgは、それが働いていないstandard dialogs
ありがとう、私はそれを働かせた。私が必要としたのは、この行でした:result = tkmessage box ...そしてresultがtrueの場合。感謝します。 –