How to make the link clickable, to be accessed?

0
print('-----')
print('SITES')
print('-----')

print()
print()




print('Duolingo Brasileiro')
print('Duolingo Inglês')
print('Duolingo Alemão')

escolha_site = str(input('Escolha qual versão do site do duolingo deseja acessar: '))


if escolha_site == 'Duolingo Brasileiro':
print('https://pt.duolingo.com/')

elif escolha_site == 'Duolingo Inglês':
print('https://en.duolingo.com/')

elif escolha_site == 'Duolingo Alemão':
print('https://de.duolingo.com/')

What I want to do is that when the user wants to access such a site, after he chooses, he could click on the link, and would be redirected to the default PC browser, in my case it's Chrome. I'm not an advanced / intermediate user of python, but I already see the need to learn a little about how to tinker with python. Remembering that these "duolingos", are just for examples, I could have used other sites as an example. Sorry for any formatting error! I'm still new here and I have a lot of work to put the code, I have to be giving spaces ... anyway, I do not know how to play much here. I used "print" only to give a rendered same, because, I do not know what command or module I will need to use to make the link clickable.

    
asked by anonymous 22.02.2017 / 20:04

1 answer

1

BRKappa,

Try to follow the example below, simply by using an HTML link:

print('<a href="http://www.exemplo.com.br">Texto do link</a>')

To open an external link in the browser, you must use the webbrowser module:

import webbrowser

webbrowser.open('https://pt.duolingo.com/')

You can use buttons and do something like this:

from Tkinter import *

app = Tk()

frame = Frame(app)
frame.pack()

url = "https://pt.duolingo.com/"

def OpenUrl():
   webbrowser.open_new(url)

button = Button(frame, text="Duolingo PT", command=lambda aurl=url:OpenUrl(aurl))
button.pack(side = "left", padx = 20, pady = 20)

app.mainloop()

The webbrowser module has the following functions:

webbrowser.open(url, new=0, autoraise=True)

Displays the URL using the default browser. If new is 0 the URL will be opened in the same browser window if possible. If new is 1, a new browser window will open if possible. If new is 2, a new browser page (tab) will open if possible. If autoraise is True , the window will be increased if possible.

webbrowser.open_new(url)

Open the URL in a new default browser window, otherwise, open the URL in the single browser window.

webbrowser.open_new_tab(url)

Opens the URL on a new default browser page (tab), if possible, otherwise does the same as open_new ()

webbrowser.get([name])

Returns a control object for the browser type. If the name is empty, it returns an appropriate driver for a default browser in the environment.

webbrowser.register(name, constructor[, instance])**

Registers the name of the browser type. Once a browser type is registered, the get() function can return a controller for that type of browser. If the instance is not provided, or is None , the constructor will be called without parameters to create an instance when needed. If the instance is provided, the constructor will never be called and can be None .

This entry point is only useful if you plan to set the BROWSER variable or call get() with a non-empty argument corresponding to the name of a handler you declare.

The webbrowser module has its documentation on the link:

22.02.2017 / 20:38