Python Forum
How to turn screen output into clickable hyperlinks - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to turn screen output into clickable hyperlinks (/thread-15547.html)



How to turn screen output into clickable hyperlinks - windros - Jan-21-2019

Hello, I am writing a program that will output a list of song titles. I want a user to be able to click a song title and then display the particular song on the screen. How do I make the titles clickable hyperlinks.

Here is part of my code:

import re
import os
os.chdir('c://users//user/Documents')
songs = open('GloriousSongsXML.txt').read()
titles = re.findall('<title>(.*)</title', songs)
for item in titles:
     print (item)
Thank you.
Windros


RE: How to turn screen output into clickable hyperlinks - ichabod801 - Jan-21-2019

To do that you are going to have to put the links in a context that understands hyperlinks. The command line doesn't understand hyperlinks, and neither does the interactive interpreter, so print isn't going to work. I think the easiest solution would be to create a simple html file. Add the links to the body of that file, and then use os.open it to open the file in the default web browser. Then they should be able to click on the links.


RE: How to turn screen output into clickable hyperlinks - windros - Jan-21-2019

I will give that a try. Thank you so much for the reply, kind Sir.

Windros


RE: How to turn screen output into clickable hyperlinks - woooee - Jan-21-2019

A second way is to use a GUI with the song title as the text on a button. Clicking the button executes a function that displays the song (however and where ever you get it from).


RE: How to turn screen output into clickable hyperlinks - snippsat - Jan-21-2019

A typicality task that i would use Flask for.
Can build sometime fast and simple to with webbrowser module.
import webbrowser, os

webbrowser.open(f'file:///{os.path.realpath("local.html")}')

# local.html
'''
<a href="file:///C:/code/Adele%20-%20Set%20Fire%20To%20The%20Rain.mp3">song1</a>
<a href="file:///C:/code/Adele%20-%20Rolling%20In%20The%20Deep.mp3">song2</a>
'''
[Image: mnTxyu.jpg]
So playing mp3 files that i have local on disk with hyperlinks.
If wonder about Path to songs,just drag them into browser and you get Path.
Quote:titles = re.findall('<title>(.*)</title', songs)
Try not to use regex for parsing html/xml,look at:
Web-Scraping part-1


RE: How to turn screen output into clickable hyperlinks - windros - Jan-22-2019

Thanks for the ideas. I was able to use html as suggested and it works fine.