python - python 3 和 tkinter 中的单选按钮

标签 python tkinter

我用 Python 3 和 Tkinter 编写了一个程序,它使用单选按钮。现在,我怎样才能使某些单选按钮已被选中?

最佳答案

您想在单选按钮上使用 select 方法,如下所示:

import tkinter as tk

root = tk.Tk()
root.title("Radio Button Example")    
button = tk.Radiobutton(root)  # Make a radio button
button.pack()  # Pack it to the screen
button.select()  #This is the bit that makes it checked
root.mainloop()

有关 tk 中 RadioButtons 的更多信息,请查看此页面的教程点:

http://www.tutorialspoint.com/python/tk_radiobutton.htm

关于python - python 3 和 tkinter 中的单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16774037/

相关文章:

python - 视频输出变成蓝色

python - 从闭包返回值并在其他模块中使用它

python - 复选按钮返回值

python - 为什么添加按钮后调节 tk Canvas 大小的关键参数不起作用?

python - 使用 pandas.IntervalIndex 作为数据帧索引

python - 注销 django web 应用程序重定向到 django 管理员注销页面。这是怎么回事?

python - WxPython 问题 : Subpanels within a Notebook Panel

Python 无法从返回的字符串中删除空格

python - 无法在flask-python中导入动态生成的sqlalchemy类

python - 如果我们最大化窗口,则调整小部件的大小