radiobutton 怎么取消默认选择
本帖最后由 lengyue869 于 2021-6-16 22:19 编辑radiobutton默认会选择第一个,checkbutton有deselect()方法可以取消选择,radiobutton有类似的方法吗?
import tkinter as tk
root=tk.Tk()
root.geometry('400x200+600+100')
plant_list=['a','b','c']
rbText=tk.IntVar()
def plant_pick():
pass
for plant in plant_list:
tk.Radiobutton(root, text=plant, value=plant_list.index(plant), variable=rbText,
command=plant_pick).grid(row=0, column=plant_list.index(plant))
root.mainloop() tk.Radiobutton(root, text=plant, value=plant_list.index(plant), variable=rbText,
AttributeError: 'NoneType' object has no attribute 'deselect'
Ctrl+.
import tkinter as tk
root=tk.Tk()
root.geometry('400x200+600+100')
plant_list=['a','b','c']
rbText=tk.IntVar()
rbText.set(None)
def plant_pick():
lb.config(text='you have selected '+plant_list)
for plant in plant_list:
tk.Radiobutton(root, text=plant, value=plant_list.index(plant), variable=rbText,
command=plant_pick).grid(row=0, column=plant_list.index(plant))
lb=tk.Label(root,text='',bg='yellow')
lb.grid(row=3,column=0)
root.mainloop()
页:
[1]