I'm kind of a newbie in python. I want to create a program that when you copy something to your clipboard, It 'prints' it on the 'app'. It works, but the issue is that every two seconds it displays what you may have copied 2 hours ago. I want it to be that when the clipboard is the same, it only shows one time and then it waits until you have copied something else. This is what i have so far
import pyperclip
from tkinter import *
r = Tk()
def aper():
global x
x = pyperclip.waitForPaste()
Label(r, text = x).pack()
r.after(2000, aper)
r.after(2000, aper)
r.mainloop()
Thank you!
you could make a variable called old_x, store the last value of x in there, and put an if-statement around the Label line, so that it only prints if x is not old_x
import pyperclip
from tkinter import *
r = Tk()
def aper():
global x
global old_x
x = pyperclip.waitForPaste()
if x != old_x:
Label(r, text = x).pack()
old_x = x
r.after(2000, aper)
old_x = None
r.after(2000, aper)
r.mainloop()