8

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()

2 Answers 2

16

There's a module for that.

import webbrowser

webbrowser.open("http://xkcd.com/353/")
Sign up to request clarification or add additional context in comments.

Comments

1

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/')
  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.