简体   繁体   中英

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

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!

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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM