python Gui... How to create a button which goes to a web page?

0 Mertcan TOK · April 15, 2015
 i was watching the tutorials about python GUI and wondered whether we can create a button which opens default web browser and goes a pre defined web page or not.
Such as clickbutton => open Mozilla °> go
Thank you

Post a Reply


Oldest  Newest  Rating
+3 alex constantin · April 15, 2015
You will have to import the webbrowser module like so and create a callback functions like this:

import webbrowser

url = ''

def openUrl():, 2) # The second parameter is todo with proxies and # other features. Number 2 is a normal open

myButton = Button(root, text='Open URL', command=openUrl)

Something like that should work. I'm pretty sure Python comes with the webbrowser module, if not, you will have to download it, but like I say, I am pretty sure it already comes with Python

Good luck
0 Mertcan TOK · April 16, 2015
i couldnt upload any image files but here is the code and it worked. Thanks for the help.

from tkinter import *
import webbrowser

url = ''

def openUrl():,2)

root = Tk()
myButton = Button(root, text='go to the new boston', command= openUrl)
0 alex constantin · April 16, 2015
No problem, glad I helped! :)
  • 1



This section is all about snakes! Just kidding.

Bucky Roberts Administrator