Python. How to print text to console as hyperlink?

旧巷老猫 提交于 2019-11-28 11:16:01

问题


I work with console application. My application uses urwid lib. In some cases I need to show very long hyperlinks into column of table as short text. I want to open link in browser onclick on text in column.

So, my question is:

It is possible to print message as hyperlink to console?

Can you provide small example how to print text as hyperlink using python?


回答1:


Yes, using some tools, like gNewt or Curses, you could create a button and 'on click' do an action (like open a browser to a given url).

gNewt : http://gnewt.sourceforge.net/

nCurses : https://docs.python.org/3.7/library/curses.html

Otherwise, it's the terminal application that will manage the text you give it, and if it doesn't implement uri's recognition your program won't work as you'd like.




回答2:


No, some consoles do recognize urls and convert them to a clickable hyperlink. All you can do is make it easy to recognize for console applications by putting a http:// in your url.

Also see How does bash recognize a link?




回答3:


This is completely not a Python question, bash itself doesn't recognize links. But some terminal emulators does. As example Gnome terminal recognize link with http://google.com or www.google.com, but not simple google.com. http:// or www indicate what this is link. Probably most other terminal emu will do same but I can't say whih exactly.



来源:https://stackoverflow.com/questions/40419276/python-how-to-print-text-to-console-as-hyperlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!