私はプログラミングの初心者です。私は趣味としてこれを行い、仕事の生産性を向上させます。
entry
ユーザーがテキスト行をコピーするたびに、クリップボードを Tkinter に自動的に貼り付けるプログラムを作成しています。
ループを使用while
して現在のクリップボードに変更があるかどうかを検出し、新しくコピーしたクリップボードのテキストを Tkinter エントリに貼り付けます。
新しいテキスト行をコピーすると、GUI が完全に更新されます。
しかし、GUI が応答せず、 をクリックしてTK entry
必要なものを入力することができません。
参考までに、私はPython 3.5
ソフトウェアを使用しています。前もって感謝します。
私のコード:
from tkinter import *
import pyperclip
#initial placeholder
#----------------------
old_clipboard = ' '
new_clipboard = ' '
#The GUI
#--------
root = Tk()
textvar = StringVar()
label1 = Label(root, text='Clipboard')
entry1 = Entry(root, textvariable=textvar)
label1.grid(row=0, sticky=E)
entry1.grid(row=0, column=1)
#while loop
#-----------
while(True): #first while loop: keep monitoring for new clipboard
while(old_clipboard == new_clipboard): #second while loop: check if old_clipboard is equal to the new_clipboard
new_clipboard = pyperclip.paste() #get the current clipboard
print('\nold clipboard pre copy: ' + old_clipboard)
old_clipboard = new_clipboard #assign new_clipboard to old_clipboard
print('current clipboard post copy: ' + old_clipboard)
print('\ncontinuing the loop...')
textvar.set(old_clipboard) #set the current clipboard to GUI entry
root.update() #update the GUI
root.mainloop()