####前提・実現したいこと
python/tkinterでwindows付箋を持つプログラムを作っています。
付箋機能の様にシャットダウンした時に入力状態を保持したいので
開いた際にテキスト読み込みを行い、
×ボタンを押した際にテキスト出力をするようにしています。
windowsをシャットダウンした時にテキスト出力するなど、
シャットダウン時のイベントをプログラムに実装することはできますか?
または、他のやり方がありますでしょうか?
環境
windows7 pro
python 3.6(anaconda 3.6)
####ソースコード
#! /usr/bin/env python import tkinter as tk import tkinter.ttk as ttk #tkinter\messagebox.py を import import tkinter.messagebox #ウィンド ウィジェットを生成 root = tk.Tk() root.title('fusen') root.minsize(350, 250) root.geometry('-10+10') root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1) root.overrideredirect(1) #テキストを生成 text_widget = tk.Text(root,bg='#ffc0f0',bd=0,state=tk.NORMAL,padx=0,pady=0,selectborderwidth=0) text_widget.grid(column=0, row=0, sticky=(tk.N, tk.S, tk.E, tk.W)) #テキストにファイルを読み込む file_value = open('./fusen.txt').read() text_widget.insert('1.0',file_value) #バツボタンでテキストをファイルに保存する def on_closing(): text = text_widget.get("1.0",'end-1c') f = open('./fusen.txt', 'w') # 書き込みモードで開く f.write(text) # 引数の文字列をファイルに書き込む f.close() # ファイルを閉じる root.destroy() #入力待ち root.protocol("WM_DELETE_WINDOW", on_closing) root.mainloop()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/12 02:49 編集