I need a little script which put the content of the clipboard in a variable and then "do things" (i.e. execute other functions with the variable as parameter). The script has to do it every time the clipboard is modified.
Right now I have:
def get_clipboard():
root = Tk()
root.withdraw()
try:
return root.clipboard_get()
except:
return ""
if __name__ == '__main__':
cb = ""
while True:
cb_new = get_clipboard()
if cb_new == cb or cb_new == "":
continue
cb = cb_new
print(cb) # Here I will call other functions
print("---------------------------------------------")
time.sleep(0.1)
But I have an error after some time: unable to realloc 28675 bytes
. I guess it is because of the while
loop, but I don't know how to do it differently. I tried to use mainloop
, but I don't understand how it work and if it is what I need.