Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programatically opening URLs in web browser in Python

I have a tkinter script. I was wondering is there anyway to have is so when you hit a button it takes you to a Web Site

from tkinter import *
app = Tk()
app.geometry("250x400")
app.title("Links")

def Link():
    ?

button1 = Button(app, text = "To a web site.", command = Link)
button1.pack()

app.mainloop()
like image 708
user1031493 Avatar asked Nov 05 '11 23:11

user1031493


2 Answers

There's a module for that.

import webbrowser

webbrowser.open("http://xkcd.com/353/")
like image 56
Petr Viktorin Avatar answered Oct 22 '22 04:10

Petr Viktorin


Use webbrowser module to open the URL. The documentation: https://docs.python.org/3/library/webbrowser.html

# You can use open 
from webbrowser import open
def link():
    open('https://www.youtube.com/')
# You can use open_new_tab
from webbrowser import open_new_tab
def link():
    open_new_tab('https://www.youtube.com/')
  
like image 29
Mohammad Al Jadallah Avatar answered Oct 22 '22 05:10

Mohammad Al Jadallah