【发布时间】:2020-09-14 00:22:27
【问题描述】:
我创建了创建作物列表的检查按钮。我想打印用户选择的裁剪,但它总是给我打印相同的裁剪(和我没有选择的裁剪)有人知道穿了什么吗?
def set_check(event):
global b
var_lst=[]
for widget in radios:
widget.destroy()
if cb_elemnt.get(): # get the crops according to element selection
if cb_elemnt.get() != "N":
crop_values =
pd.unique(df.loc[df["elemnt"].eq(cb_elemnt.get()),"crop"])
else:
crop_values = pd.unique (df_nir.loc[df_nir["elemnt"].eq
(cb_elemnt.get ()), "crop"])
for num, t in enumerate(crop_values, 1): # create and add the crops to check button with number start from
chkValue =IntVar ()
checkbox_variable = IntVar ()
# I need seperate var for each crop
b = Checkbutton (top, text=t, variable=checkbox_variable, font=("Segoe UI Light", 10))
checkbox_variables.append (checkbox_variable)
b.grid (row=num, column=2, sticky='W', padx=40)
radios.append (b)
def regression():
#PLSR
if cb_elemnt.get () != "N":
if var1.get():
element_u= cb_elemnt.get () #The element that the user selected
print(element_u)
for checkbox in checkbox_variables:
if checkbox.get ()==1:
print(b.cget("text"))
【问题讨论】:
-
您可以将
onvalue = 1, offvalue = 0设置为Checkbutton -
默认没有?我正在尝试打印用户标记的按钮的文本,无论我选择什么,它总是打印相同的文本
标签: python user-interface tkinter