When I run the code without copying anything, it will give an error. It works fine if I initially copy some string then run the code (see this clip).
I want the code to run just fine even if I initially didn't copy any string, then If I did copy some it will slice the string.
from tkinter import *
from tkinter import Tk
from urllib import parse
root = Tk()
root.geometry('304x70')
lbl=Label(root, text = "Nothing Here")
lbl.pack()
def check_clipboard(window):
clip = root.clipboard_get()
clip = parse.unquote(clip)[45:]
root.clipboard_clear()
root.clipboard_append(clip)
lbl.configure(text= clip)
def run_listener(window, interval):
check_clipboard(window)
root.after(interval, run_listener, window, interval)
# Not sure what to put here:
#try:
# ???
#except:
# ???
run_listener(root, 5000)
root.mainloop()
I look to some posts [1, 2] that uses try.. except.. but I can't find them working for my specific issue.