I don’t think that you have to do anything special. The document that you are writing the text to should auto-recognize that it is a link. I am currently creating a .pdf document which includes writing a url. When I open the document, and hover my mouse over it, it recognizes that it is a link and the mouse pointer which is an arrow, automatically turns into a hand, implying that it is a link.
The same should work if you’re creating a Word, Excel, etc., document.
Here is a small script. It will create a document and it will save it to your desktop for easy referencing. Note that I did not do anything special.
import os
os.chdir(r'C:\Desktop')
from fpdf import FPDF
# Prepare PDF generator
pdf = FPDF(orientation = 'P', unit = 'mm', format = 'letter') # Set format and unit
pdf.add_page()
# Write to page
pdf.set_font(family='arial', size=12, style='')
pdf.set_y(100)
pdf.set_x(100)
pdf.cell(w=0, txt='www.python.org', align='L')
# # Output the PDF
pdf.output("url_test.pdf")
hey Paul,
thanks very much for your help! your code was very insightful. i’m going to use it to learn python. thank you!
the thing is is that i’m making some sort of program in VS code and my text in my text widget is selectable and stuff. i’m not very experienced with python so i’m not sure where to look.
I misundertood (misread) your problem. I thought you wanted to know how to write text (which happens to be a link), to a document, and make it clickable.
From the first quote above, do you mean that you want to be able to “click” the variable item_name and have it take you to the url that robloxItemLink is assigned to? Can you elaborate further please. This will help with the second quote.
I did a search for “add clickable text to tkinter Text widget” and among others it came up with the result Tkinter Text Widget With Example - python-hub where there’s an example under the heading " Embedding Links (Sort of)"
Here is a slightly modified test script from the link that @avisser provided. You have to import the webbrowser library package to make it work. The call back function includes the action of opening the url of your choice. You can edit it as per your project requirements (for testing purposes, I included www.python.org). I am using Windows 11. To open the link, you have to simultaneously press the CTRL key when clicking the variable item_name.