Python Forum
How to turn screen output into clickable hyperlinks
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to turn screen output into clickable hyperlinks
#1
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
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
I will give that a try. Thank you so much for the reply, kind Sir.

Windros
Reply
#4
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).
Reply
#5
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
Reply
#6
Thanks for the ideas. I was able to use html as suggested and it works fine.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Sad "Disabled" Buttons Still Clickable. Nd4SpdSe 3 325 Mar-13-2024, 07:44 AM
Last Post: laughorchestra
  How to "tee" (=split) output to screen and into file? pstein 6 1,371 Jun-24-2023, 08:00 AM
Last Post: Gribouillis
  Turn coordinates in string into a tuple Kolterdyx 3 2,741 Jun-10-2020, 05:04 AM
Last Post: buran
  How do i turn my program into a .exe julio2000 1 1,880 Feb-14-2020, 08:18 PM
Last Post: snippsat
  How do I turn a directory of HTML files into one CSV? glittergirl 2 1,792 Sep-21-2019, 05:33 PM
Last Post: glittergirl
  Turn py into exe tester21 4 3,026 Jul-22-2019, 04:31 PM
Last Post: nilamo
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,171 Feb-06-2019, 01:25 AM
Last Post: woooee
  Not sure how to turn this into a loop iamgonge 1 2,080 Dec-05-2018, 11:03 PM
Last Post: anandoracledba
  How to run a python file from html hyperlinks dhinahar 0 2,360 Jul-04-2018, 05:07 PM
Last Post: dhinahar
  Having my output links become clickable bigmit37 8 29,671 May-25-2017, 08:17 PM
Last Post: bigmit37

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020