Skip to content

Instantly share code, notes, and snippets.

@RandomResourceWeb
Created July 17, 2016 08:57
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RandomResourceWeb/93e887facdb98937ab5d260d1a0df270 to your computer and use it in GitHub Desktop.
Save RandomResourceWeb/93e887facdb98937ab5d260d1a0df270 to your computer and use it in GitHub Desktop.
How to open a link through a tkinter button in Python
#---------------------------------
# Random Resource Web ©
# Randomresourceweb.blogspot.com
#---------------------------------
from tkinter import *
import webbrowser
root = Tk()
new = 1
url = "https://www.google.com"
def openweb():
webbrowser.open(url,new=new)
Btn = Button(root, text = "This opens Google",command=openweb)
Btn.pack()
root.mainloop()
@greeenboi
Copy link

can you guys try the same with custom tkinter? it doesn't seem to work as i intended

@ldrak20
Copy link

ldrak20 commented May 22, 2023

is there a way to add this with radio buttons, like if optionA is selected it opens linkA... ect ect?

@TheTechRobo
Copy link

@ldrak20 Well yes, the important part is the use of webbrowser.open function. You can call it from wherever you'd like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment