设计一个单选按钮,在点击不同按钮时,返回不同的值
注意字符型变量的转换
import tkinter as tk
root = tk.Tk()
root.title("请选择编程语言")
root.geometry("600x400")
a = tk.StringVar() #设置一个字符型变量
label = tk.Label(root,textvariable=a,width=50,height=10,font=("Arial",15))
label.pack()
b = tk.StringVar()
b.set("1")
def mClike():
#global a
var = b.get()
print(var)
a.set(chr(65+int(var)))
radio = tk.Radiobutton(root,variable=b,value=0,text="python",command=mClike)
radio.pack()
radio = tk.Radiobutton(root,variable=b,value=1,text="java",command=mClike)
radio.pack()
radio = tk.Radiobutton(root,variable=b,value=2,text="c++",command=mClike)
radio.pack()
radio = tk.Radiobutton(root,variable=b,value=3,text="c语言",command=mClike)
radio.pack()
root.mainloop()