Create links that can be copied or clicked on Tkinter

Asked

Viewed 44 times

0

I created a script basically to replace links by removing some special characters. It’s functional. The problem is only the data output, because I am putting to present a label, with the link already without the special characters, so it is not possible to copy the link through the interface. Is the result of this script to be presented in a way that is possible to copy the link, or click? In addition, it is possible that when the script output is larger than the program interface, there is an automatic line break?

from tkinter import *

conversor = Tk()
conversor.title("CONVERSOR DE LINKS")
conversor["bg"] = "white"
conversor.geometry("600x300")


entrada1 = Entry(conversor)
entrada1.place(width= 500, x=50, y=100)

def bt_converter():
    link = (entrada1.get())   
    link = link.replace("%2f", "/")
    link = link.replace("%3f", "?")
    link = link.replace("%3d", "=")
    retorno["text"] = link

btenvio = Button(conversor, width=20, text="Converter", command=bt_converter)
btenvio.place(x=230, y=130)

lb = Label(conversor, text= "DIGITE O LINK")
lb.place(x=180, y=70)

lbretorno = Label(conversor, text="LINK UTILIZÁVEL")
lbretorno.place(x=250, y=180)

retorno = Label(conversor, text="")
retorno.place (width= 500, x=50, y=210)

conversor.mainloop()

1 answer

0

Tkinter itself has an access to Clipboard, which in this case is Ctrl C. Perhaps a way would be after generating the converted text appear a button that calls a function that makes the following logic

conversor.clipboard_clear()
conversor.clipboard_append(suaVariavelDeRetorno)
conversor.update() # salva o Ctrl+C mesmo se o programa fecha
  • Thanks friend. I created a button called copy, I defined a method with this Clipboard and it worked right. I also created another to access, using callback!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.