我有一个表单,用户通过单击按钮创建产品属性的记录。单击后,四个组合框、一个标签和一个输入字段将加载到构成记录的表单上
第四个组合框上的下拉列表取决于前三个组合框中的条目。最终用户可能会在输入之前多次单击“添加”按钮。我如何确保当用户在单击“添加”按钮“N”次后返回第一条记录并更改第一条记录的组合框时,在第四个组合框中加载适当的值
这是我的
def addItemInEdit():
global rowNum2
global brandDropdownList2, typeDropdownList2, sizeDropdownList2, qtyTextList2, itemList2,
packedDateDropdownList2
####################### Loading label, dropdowns, and text fields
itemList2.append(ttk.Label(frameEdit, text=str(rowNum2 + 1) + ". ").grid(row=rowNum2, column=0))
brandDropdownList2.append(ttk.Combobox(frameEdit, state='readonly', values=listOfBrands, width=10))
brandDropdownList2[-1].grid(row=rowNum2, column=1, pady=5, padx=5)
brandDropdownList2[-1].current(0)
typeDropdownList2.append(ttk.Combobox(frameEdit, state='readonly', values=listOftypes, width=5))
typeDropdownList2[-1].grid(row=rowNum2, column=2)
typeDropdownList2[-1].current(0)
sizeDropdownList2.append(ttk.Combobox(frameEdit, state='readonly', values=listOfSizes, width=10))
sizeDropdownList2[-1].grid(row=rowNum2, column=3, pady=5, padx=5)
sizeDropdownList2[-1].current(0)
packedDateDropdownList2.append(ttk.Combobox(frameEdit, state='disabled', width=7))
packedDateDropdownList2[-1].grid(row=rowNum2, column=4, pady=5)
qtyTextList2.append(ttk.Entry(frameEdit, width=7))
qtyTextList2[-1].grid(row=rowNum2, column=5, padx=5)
qtyTextList2[-1].insert(0, "Qty")
####################### Adding bind functions.
for item in range(len(brandDropdownList2)):
def getDates(event):
listOfDates=[]
################################## Making sure the use has made actual selections
if brandDropdownList2[len(brandDropdownList2)-1].get()!="Brand" and typeDropdownList2[len(brandDropdownList2)-1].get()!="Type" and sizeDropdownList2[len(brandDropdownList2)-1].get()!="Size":
packedDateDropdownList2[len(brandDropdownList2) - 1].config(state='readonly')
packedDateDropdownList[len(brandDropdownList) - 1].set('')
getDatesQuery = "SELECT [PackedOn] FROM SalesData where [Brand]=? AND [Type] = ? AND [Size]=?"
conForDates = pyodbc.connect(dbPath)
curForDates = conForDates.cursor()
dateListOutput = curForDates.execute(getDatesQuery,(brandDropdownList2[len(brandDropdownList2)-1].get(),typeDropdownList2[len(brandDropdownList2)-1].get(),sizeDropdownList2[len(brandDropdownList2)-1].get())).fetchall()
for item in dateListOutput:
if item[0] not in listOfDates:
listOfDates.append(item[0])
packedDateDropdownList2[len(brandDropdownList2)-1].config(values=listOfDates)
else:
packedDateDropdownList2[len(brandDropdownList2) - 1].set('')
packedDateDropdownList2[len(brandDropdownList2) - 1].config(state='disabled')
brandDropdownList2[len(brandDropdownList)-1].bind("<<ComboboxSelected>>",getDates)
typeDropdownList2[len(brandDropdownList)-1].bind("<<ComboboxSelected>>",getDates)
sizeDropdownList2[len(brandDropdownList)-1].bind("<<ComboboxSelected>>",getDates)
rowNum2 = rowNum2 + 1
我知道绑定的“For”循环是错误的,但我觉得Python有一个我不知道的特性
getDates()
函数总是从最后一行获取值 不正确的组合框李>getDates()
放在addItemInEdit()
函数之外李>以下是您的代码的修改版本:
相关问题 更多 >
编程相关推荐