Home > database >  How do I assign a website URL as the value of a selected radiobutton in a Python GUI using Tkinter?
How do I assign a website URL as the value of a selected radiobutton in a Python GUI using Tkinter?

Time:05-22

I currently have an assignment for University where I have to develop a GUI using Tkinter in Python which displays multiple options whose purpose is display certain information based on what radio button is selected.

My question is, how do I assign something like a website value to a radio button selection?

I want to assign a different website to each of my 3 radio buttons which is the main source used when I press on any of the options.

For example, I have display details as one of my options, and I wish for that widget when pressed to open a website depending on which radio button is selected.

Thanks!

CodePudding user response:

What I understood from your question is that you want to use a button in tkinter to make you access a certain website.

I would like to suggest this :

import webbrowser
from tkinter import Button, Tk

root = Tk()

def web(site):    #function that opens a website in a new window
    webbrowser.open(site, new = 2)    #new = 2 means new window, 1 means new tab, 0 means replace the current window

b = Button(root, text = "google", command = lambda : [web("www.google.com")])
b.pack()

root.mainloop()

I hope it helps you in your current assignment, good luck !

  • Related