我正在制作一个程序来搜索股票编号列表(列表中的前 8 位整数),然后在输入框内返回列表中的其余值,但是当我单击搜索按钮时,它不执行它功能。有什么建议吗?(我也是编码新手,有什么地方可以缩短我的代码以提高效率吗?)
root = Tk()
#lists
car = [19225735, '611926', '2018', 'Hyundai', 'Sonata', 'White', 'Recon', '$25,000',
'Sedan',32,123]
#funtion
def search():
x = stockNumber.get()
if (x == car[0]):
vinNumber.insert(car[1])
make.insert(car[3])
model.insert(car[4])
color.insert(car[5])
status.inset(car[6])
price.insert(car[7])
size.insert(car[8])
mileage.insert(car[9])
#text boxes --------------------------------------------
stockNumber = Entry(root, width=30)
stockNumber.grid(row=0, column=1, padx=20)
vinNumber = Entry(root, width=30)
vinNumber.grid(row=1, column=1, padx=20
year = Entry(root, width=30)
year.grid(row=2, column=1, padx=20)
make = Entry(root, width=30)
make.grid(row=3, column=1, padx=20)
model = Entry(root, width=30)
model.grid(row=4, column=1, padx=20)
color = Entry(root, width=30)
color.grid(row=5, column=1, padx=20)
status = Entry(root, width=30)
status.grid(row=6, column=1, padx=20)
price = Entry(root, width=30)
price.grid(row=7, column=1, padx=20)
size = Entry(root, width=30)
size.grid(row=8, column=1, padx=20)
mileage = Entry(root, width=30)
mileage.grid(row=8, column=1, padx=20)
#button command-------------------------------
enter = Button(root, text = "Search", padx=40, pady=20, command=search)
enter.grid(row=9, column=0)
#labels ------------------------------------------------
snLabel = Label(root, text="Stock Number")
snLabel.grid(row=0, column=0)
vnLabel = Label(root, text="Vin Number")
vnLabel.grid(row=1, column=0)
yearLabel = Label(root, text="Year")
yearLabel.grid(row=2, column=0)
makeLabel = Label(root, text="Make")
makeLabel.grid(row=3, column=0)
modelLabel = Label(root, text="Model")
modelLabel.grid(row=4, column=0)
colorLabel = Label(root, text="Color")
colorLabel.grid(row=5, column=0)
statusLabel = Label(root, text="Status")
statusLabel.grid(row=6, column=0)
sizeLabel = Label(root, text="Size")
sizeLabel.grid(row=7, column=0)
mileLabel = Label(root, text="Mileage")
mileLabel.grid(row=8, column=0)