我正在尝试创建餐厅管理系统,我设计了食物和其他服务以在按钮中表示,因此只需按一下按钮即可保存按钮的名称和文本框中的点击次数(收据)。它看起来像这样:
我的问题是如何获取for循环生成的按钮文本并插入文本框
这是我的代码的一部分:
def readbreakfast(): #this reads food names from database
cur.execute("SELECT name FROM breakfast")
return cur.fetchall()
def showbreakfast(): #this reads names into buttons
global name
data1 = readbreakfast()
for index, dat in enumerate(data1):
name= ttk.Button(master, text=dat[0],command=lambda row=index+1:update_count(row))
name.grid(row=index+1, column=0,padx=0, pady=0)
def update_count(value): #this gets button name and number of clicks
global bttn,bttn_clicks,my_text
my_text=StringVar()
my_text = dat.cget('text')
bttn_clicks += 1
bttn = IntVar()
global variable
variable = value
print(update_count)
def Receipt(): #text of the button that is clicked is to insert here
txtReceipt.delete("1.0", END)
x = random.randint(10908, 500876)
randomRef = str(x)
Receipt_Ref.set("BILL" + randomRef)
txtReceipt.insert(END, 'Receipt Ref: \t\t\t'+Receipt_Ref.get()+"\t\t"+DateofOrder.get()+"\n")
txtReceipt.insert(END, 'Items\t\t'+'Quantity\t\t\t'+"Price \n\n")
if variable == 1:
txtReceipt.insert(END, str(my_text)+'\t\t'+str(bttn_clicks)+'\t\t\t'+""+str(bttn_clicks*3)+"\n")
if variable == 2:
txtReceipt.insert(END, str(my_text)+'\t\t'+str(bttn_clicks)+'\t\t\t'+""+str(bttn_clicks*3)+"\n")
I have found different code examples but nothing specific enough to implement into my program. Any advice is much appreciated!