I'm trying to make a link slicer that automatically slice and copy the sliced output of the link right after I pasted it on txt = Entry(window,width=50)
without clicking a button.
When I paste a link something like this: http://url.io/s/1234abcd/?s=https%3A%2F%2Fexample.com%2Fsome_contens%2F
then it will become: example.com/some_contents/
Right now the code below is what I use, but I still have to click the "slice" button before "slicing" and "copying" happens.
from tkinter import *
from urllib import parse
from tkinter import Tk
window = Tk()
window.title("Link Slicer")
window.geometry('344x50')
lbl = Label(window, text="Link")
lbl.grid(column=0, row=1)
txt = Entry(window,width=50)
txt.grid(column=0, row=0)
def clicked():
sliced = txt.get()
sliced = parse.unquote(sliced)
lbl.configure(text= sliced[36:])
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(sliced[36:])
r.update()
btn = Button(window, text="Slice", command=clicked)
btn.grid(column=1, row=0)
window.mainloop()
I made this code below to try to automate "slicing" and "copying" right after I paste the link in the txt = Entry(window,width=50)
without clicking a button (which doesn't work):
from tkinter import *
from urllib import parse
from tkinter import Tk
window = Tk()
window.title("Link Slicer")
window.geometry('344x50')
lbl = Label(window, text="Link")
lbl.grid(column=0, row=1)
txt = Entry(window,width=50)
txt.grid(column=0, row=0)
sliced = txt.get() // 1. automatically get what's in txt = Entry(window,width=50)
sliced = parse.unquote(sliced) // 2. auto-slice
r = Tk() }
r.withdraw() }
r.clipboard_clear() } // 3. auto-copy
r.clipboard_append(sliced[36:]). }
r.update() }
window.mainloop()