import tkinter
win = tkinter.Tk()
win.title("Radiobutton單選框")
win.geometry("800x600+600+100")
def updata():
print(r.get())
#一組單選框要綁定同一個變量
r=tkinter.IntVar()#給單選框添加variable,用於顯示value值
radio1=tkinter.Radiobutton(win,text="one",value=1,variable=r,command=updata)
radio1.pack()
#value值不能相同,才能實現單選
radio2=tkinter.Radiobutton(win,text="two",value=2,variable=r,command=updata)
radio2.pack()
radio3=tkinter.Radiobutton(win,text="tre",value=3,variable=r,command=updata)
radio3.pack()
win.mainloop()
