错误信息是文本框内显示PY_VAR24 之类的英文字母,而不是[‘请选择’,‘教师’,‘学生’],
不能设为 IntVar()
,只有current
方法才能获取 0,1,2…索引值
combobox_Var = IntVar()
combobox = ttk.Combobox(labelframe,
values = ['请选择','教师','学生'], ######## values是用来输入列表值用的 #####
width=8,
font=('microsoft yahei', 10, 'bold'),
state = 'readonlly',
value = combobox_Var, ######## 此处不应该为 value########
)
combobox_Var = StringVar() ####### 因为框内是 ['请选择','教师','学生'],这样的字符型###########
combobox = ttk.Combobox(labelframe,
values = ['请选择','教师','学生'],
width=8,
font=('microsoft yahei', 10, 'bold'),
state = 'readonlly',
textvariable = combobox_Var, ######## 此处是指 ['请选择','教师','学生']#########
)
############# 要想获得 index索引值 0,1,2...........
combobox_index = combobox.current()
############# 要想获得 文本值 ['请选择','教师','学生']
combobox_text = combobox.get()
check_agree_value = IntVar() ############ 此处是 整型变量,因为对应 0或1的值 ####
check_agree = Checkbutton(myWindow,
text = '同意声明',
variable = check_agree_value, ########### 此处用的就是 variable 来指定变量,不是用 textvariable ##########
fg = 'DodgerBlue',
width = 15,
cursor = 'heart',
font = ('microsoft yahei', 10,'bold','roman',UNDERLINE)
)