今回は、メールのテンプレートを毎回コピーするのが面倒だった為
それ専用のソフトを自分で作ってみました。
(最下部pythonコード記載)
動作としては、テキストファイル(.txt)の名前を表示し
それをクリックすると、テキストファイルの中身がコピーされます
📌マークで、画面の最前面に固定し、+-ボタンで文字サイズを変更
実際のファイルは、1枚目の画像にあるtxt_to_clipboard.exeで
開かれたソフトは、2枚目の画像です
ソフトと同じフォルダにあるものを読込します
ファイルの名前順でソフトに表示する為、先頭に番号を入れれば
その順番で表示されます(txtファイルのみ)
使い方は、ソフトに表示されたファイル名をクリック
あとは Ctrl + V 等で貼付けるだけです。
ちなみに、ソフトを使わずにテンプレート文を入力する方法もあり
その一つに辞書ツールで単語の登録を使って
例えば「あ」を変換すれば「誠に有難うございました」等の
長い文章を出す事は出来ますが、会社でテンプレート文を使う場合は
なるべく全体で統一し、変更があれば全体を更新する必要があります
このソフトを使えば、共有フォルダにこのソフトを設置し
各PCからショートカットを使って起動すれば、全員が同じテンプレート
を使用出来ますし、変更があれば即座に更新されます
ダウンロード、利用は自己責任でお願いします。
いかなる場合であっても、筆者は責任を負いません。
(エラー報告があれば助かります)
import tkinter as tk
import pyperclip
import glob
from natsort import natsorted
items = [filename.replace('.txt', '') for filename in natsorted(glob.glob('*.txt'))] # ファイル名取得
bool0 = False
bool1 = True
height_pix = 20
Width_pix = height_pix * 15
f = ("",int(height_pix/2 - height_pix/20 + 1.3)) # 文字サイズで、ボタンの高さを決める
def size_update():
global height_pix
global Width_pix
global f
Width_pix = height_pix * 15
f = ("",int(height_pix/2 - height_pix/20 + 1.3)) # 文字サイズで、ボタンの高さを決める
class Application(tk.Frame):
def on_close(self):
global bool1
bool1 = False
self.master.quit() # プログラムを終了する
def __init__(self, master=None):
size_update()
super().__init__(master)
# 画面サイズ
size_height = str(height_pix + (height_pix + 4)*len(items))
self.master.geometry(f'{Width_pix}x{size_height}+600+200')#570
# 画面タイトル
self.master.title('コピー')
self.frame1 = tk.Frame(self.master, width=Width_pix, height=height_pix + (height_pix + 4)*len(items))#475
self.frame1.grid_propagate(False)
self.frame1.place(x=0, y=height_pix)
#ウィジェット作成
self.create_widgets()
self.create_pin()
self.create_size_edit()
# ウィンドウのクローズイベントをキャッチしてプログラムを終了
master.protocol("WM_DELETE_WINDOW", self.on_close)
def create_pin(self):
size_update()
def topmost():
def bt():
global bool0
global height_pix
if bool0 == False:
bool0 = True
self.master.attributes('-topmost', True)
else:
bool0 = False
self.master.attributes('-topmost', False)
return bt
#ピン止めボタン
self.button0 = tk.Button(text="📌", anchor=tk.S, font=f, command=topmost())
self.button0.place(x=0, y=0, width=height_pix, height=height_pix)
def create_size_edit(self):
size_update()
def size_up():
def bt():
global height_pix
if height_pix < 35:
height_pix += 2
self.master.destroy()
return bt
def size_down():
def bt():
global height_pix
if height_pix > 15:
height_pix -= 2
self.master.destroy()
return bt
global f
#サイズアップボタン
self.button_up = tk.Button(text="+", anchor=tk.S, font=f, command=size_up())
self.button_up.place(x=height_pix, y=0, width=height_pix, height=height_pix)
#サイズダウンボタン
self.button_down = tk.Button(text="-", anchor=tk.S, font=f, command=size_down())
self.button_down.place(x=height_pix*2, y=0, width=height_pix, height=height_pix)
def create_widgets(self):
size_update()
def click_button(item):
def bt():
with open(items[item] + '.txt', 'r') as f:
data = f.read()
pyperclip.copy(data)
return bt
self.buttons = []
for i, item in enumerate(items):
self.buttons.append(str(item))
self.button = tk.Button(self.frame1, text=item, anchor=tk.W, font=f, width=Width_pix, height=1,command=click_button(i))
self.button.grid(row=i)
def main():
global bool1
while bool1:# サイズ変更の際に、ウィンドウを作り直す
root = tk.Tk()
app = Application(master=root)
app.mainloop()
if __name__ == "__main__":
main()
#--------------------------ここまで
文字サイズ、ボタンサイズの変更が面倒なので
ウィンドウを毎回削除してます。
ご拝読ありがとうございます