我正在 tkinter 中研究 python gui 并尝试使用单位转换器。最初,当我将光标放在较低的单选按钮上时,它们会自动被选中,请任何人帮助我如何摆脱它。
from Tkinter import *
import tkMessageBox
root=Tk()
root.wm_title("Measurement Converter")
def Distance():
def sel():
print var.get()
L1 = Label(root, text="Enter Value :",font=20)
L1.grid(row=3,column=0,padx=(0,10),columnspan=2)
E1=Entry(root,justify=CENTER,width=20).grid(row=3,column=1,padx=(0,0),ipady=10,ipadx=20)
L2 = Label(root, text="units in-")
L2.grid(row=4,column=1,padx=(0,0))
var = IntVar()
R1 = Radiobutton(root, text="Meter", variable=var, value=1,command=sel)
R1.grid(row=4,column=1,padx=(120,0))
R2 = Radiobutton(root, text="Km", variable=var, value=2,command=sel)
R2.grid(row=4,column=1,padx=(240,0))
R3 = Radiobutton(root, text="Feet", variable=var, value=3,command=sel)
R3.grid(row=4,column=1,columnspan=2,padx=(100,0),pady=4)
L3 = Label(root, text="convert into-")
L3.grid(row=5,column=1,padx=(0,0))
var3 = IntVar()
RB1 = Radiobutton(root, text="Meter", variable=var3, value=1,command=sel)
RB1.grid(row=5,column=1,padx=(120,0))
RB2 = Radiobutton(root, text="Km", variable=var3, value=2,command=sel)
RB2.grid(row=5,column=1,padx=(240,0))
RB3 = Radiobutton(root, text="Feet", variable=var3, value=3,command=sel)
RB3.grid(row=5,column=1,columnspan=2,padx=(100,0),pady=5)
label1=Label(root, text='Select any Button to convert it in other Unit',bg="green",fg="white",justify=CENTER,borderwidth=1,font=20,padx=20 )
label1.grid(pady=15,padx=(15,15),row=0,column=1)
buttontext1=StringVar()
button1=Button(root,textvariable=buttontext1,font=25,padx=5,pady=5,width=15,command=Distance,bg='#FF0000')
buttontext1.set("Distance")
button1.grid(row=1,column=0,padx=(100,00))
buttontext2=StringVar()
button2=Button(root,textvariable=buttontext2,font=25,padx=5,pady=5,width=15,command=Distance,bg='#66FF66')
buttontext2.set("Weight")
button2.grid(row=1,column=2,padx=(0,100))
buttontext3=StringVar()
button3=Button(root,textvariable=buttontext3,font=25,padx=5,pady=5,width=15,command=Distance,bg='#3399CC')
buttontext3.set("Temprature")
button3.grid(row=2,column=0,pady=50,padx=(100,0))
buttontext4=StringVar()
button4=Button(root,textvariable=buttontext4,font=25,padx=5,pady=5,width=15,command=Distance,bg='#CCFF00')
buttontext4.set("Volume")
button4.grid(row=2,column=2,padx=(0,100))
root.mainloop()