想要制作我在人物旁边放置写/添加新栏的按钮(我已经制作了识别人物的代码),但我试图允许csv文件用所有旧信息重写,另外还有一列,用户将从3个按钮中选择一个来填充,这就是我迄今为止所尝试的
#opening the csv file
filepath = 'file name'
csvFile = open(filepath)
#reader through the csv file
reader = csv.reader(csvFile)
# turning the csv file into a list.
Data = list (reader)
list_of_entries = []
list_of_entries.append(Data["Time"])
def TimeBTN15 ():
Data["Time"] = '15 mins'
Data["Time"] = newtime
def TimeBTN30 ():
Data["Time"] = '30 mins'
Data["Time"] = newtime
def TimeBTN1 ():
Data["Time"] = '1 Hour'
Data["Time"] = newtime
TimeLBL = Label(frame3,text="What time would you like to pick up meal:",font=('Arial',18, "bold"),bg = '#F0EAD6')
TimeLBL.place(x= 80, y= 575)
TimenBTN15 = Button(frame, text = '15 mins', font=('Arial',16,),bg = '#F0EAD6',command = TimeBTN15 )
TimenBTN15.place(x= 450, y= 575)
TimenBTN30 = Button(frame, text = '30 min ', font=('Arial',16,),bg = '#F0EAD6',command = TimeBTN30 )
TimenBTN30.place(x= 525, y= 575)
TimenBTN1 = Button(frame, text = ' 1 hour', font=('Arial',16,),bg = '#F0EAD6',command = TimeBTN1 )
TimenBTN1.place(x= 600, y= 575)
csvFile = open('shopoutput.csv', 'w+')
# writting in the headers
csvFile.write("Name,Food,Drinks,Price,NewTime\n")
#adding all the new data into the orginal and new data into the shopoutput csv
for data in list_of_entries:
csvFile.write(data['Name'] + ',')
csvFile.write(data['Food'] + ',')
csvFile.write(data['Drinks'] + ',')
csvFile.write(data['Price'] + ',')
csvFile.write(data['Time'] + '\n')
csvFile.close()
很难帮助你,因为你没有给出完整的计划。这里有很多问题
Data
是词典列表,而不是词典。您从不将任何内容复制到list_of_entries
,因此这将永远不会有您的旧数据。在用户做出某些选择之前,您无法将任何内容写入csv文件,而该选择必须是按钮响应。这里有一个例子,似乎更接近你想要的相关问题 更多 >
编程相关推荐