[英]How to display GUI message indicating which checkbutton(s) and radiobutton have been selected in tkinter in Python?
[英]How do I assign a website URL as the value of a selected radiobutton in a Python GUI using Tkinter?
我目前有一个大学任务,我必须在 Python 中使用 Tkinter 开发一个 GUI,它显示多个选项,其目的是根据选择的单选按钮显示某些信息。
我的问题是,如何将网站值之类的东西分配给单选按钮选择?
我想为我的 3 个单选按钮中的每一个分配一个不同的网站,这是我按下任何选项时使用的主要来源。
例如,我将显示详细信息作为我的选项之一,并且我希望在按下该小部件时根据选择的单选按钮打开网站。
谢谢!
我从你的问题中了解到,你想在 tkinter 中使用一个按钮来让你访问某个网站。
我想建议这个:
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()
我希望它对你当前的任务有所帮助,祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.