我想访问选定的单选按钮的值,并将其与if语句进行比较,但是在访问该值时,我得到的是PY_VAR0。
from tkinter import *
ComplaintForm=Tk()
typesel=StringVar()#<--variable I'm using to access value of selected Radiobutton
HighVoltage=Radiobutton(ComplaintForm,text='High Voltage Motor',value='HighVoltage',\
anchor=W,font='roboto 18',bg='white',variable=typesel)
HighVoltage.grid(row=5,column=1,padx=5,pady=10)
LowVoltage=Radiobutton(ComplaintForm,text='Low Voltage Motor',value='LowVoltage',\
anchor=W,font='roboto 18',bg='white',variable=typesel)
LowVoltage.grid(row=5,column=0,padx=5,pady=10)
print(typesel)#this is printing PY_VAR0 instead of accessing value of above Radiobuttons
mainloop()
PS:我知道此代码中引入了一些弊端,以使代码保持最小化,并使问题易于理解。
紫衣仙女
相关分类