【发布时间】:2018-05-14 08:27:52
【问题描述】:
我正在为咖啡馆管理系统制作一个简单的程序,它将食物名称作为按钮从桌子上读取,我还想从桌子上读取食物价格并将其乘以按钮点击次数,然后将它们保存到Text我该怎么做呢
this is the image that show where are the two main isues are
from tkinter import *
from tkinter import ttk
import sqlite3
import time
import datetime
import random
variable = 1
bttn_clicks=0
button_dict = {}
button_dic = {}
conn = sqlite3.connect('hoteldb.db')
c = conn.cursor()
def showqurec():
global button,data2
data2 = readqurec()
for index, dat in enumerate(data2):
button= ttk.Button(master, text=dat[0],command=lambda dat=dat:update_count(dat))
button.grid(row=index+1, column=0,padx=0, pady=0)
button_dict[dat] = button
def showqado():
global button,data2
data2 = readqado()
for index, dat in enumerate(data2):
button = ttk.Button(master, text=dat[0],command=lambda dat=dat: update_count(dat))
button.grid(row=index+1, column=1,pady=0,padx=0)
button_dict[dat] = button
def showcasho():
global button,data2
data2 = readcasho()
for index, dat in enumerate(data2):
button=ttk.Button(master, text=dat[0],command=lambda dat=dat:update_count(dat))
button.grid(row=index+1, column=2,padx=0, pady=0)
button_dict[dat] = button
def readfromdatabase():
cur.execute("SELECT qureec.name,qado.name,casho.name FROM qureec,qado,casho")
return cur.fetchall()
def readqurec():
cur.execute("SELECT name FROM qureec ")
return cur.fetchall()
def readqado():
cur.execute("SELECT name FROM qado ")
return cur.fetchall()
def readcasho():
cur.execute("SELECT name FROM casho ")
return cur.fetchall()
def update_count(x):
global bttn_clicks,my_text,price
my_text=StringVar()
for name in data2:
my_text = button_dict[x].cget('text')
bttn_clicks += 1
def Receipt():
txtReceipt.delete("1.0", "4.0")
x = random.randint(10908, 500876)
randomRef = str(x)
Receipt_Ref.set("BILL" + randomRef)
txtReceipt.insert("1.0", 'Receipt Ref: \t\t\t'+Receipt_Ref.get()+"\t\t"+DateofOrder.get()+"\n")
txtReceipt.insert("2.0", 'Items\t\t'+'Quantity\t\t\t'+"Price \n\n")
if variable !=0:
txtReceipt.insert(END, str(my_text)+'\t\t'+str(bttn_clicks)+'\t\t\t'+""+str(bttn_clicks*3)+"\n")
master=Tk()
master.geometry('630x350+100+200')
master.title('Records')
Label = Button(master, text="meal", width=10,command=showqurec)
Label.grid(row=0, column=0)
BMILabel = Button(master, text="tea", width=10,command=showqado)
BMILabel.grid(row=0, column=1)
stateLabel = Button(master, text="fast food", width=10,command=showcasho)
stateLabel.grid(row=0, column=2)
lblReceipt = Button(master,text="Get Receipt:",anchor='w',command=Receipt)
lblReceipt.grid(row=0,column=4,sticky=W)
txtReceipt = Text(master,bg="white",width=47,height=17.5)
txtReceipt.grid(row=1,column=4,rowspan=4,columnspan=40)
Receipt_Ref=StringVar()
DateofOrder = StringVar()
master.mainloop()
现在我宣布了价格,但我如何从数据库中获取它们 我还有另一个按钮点击在每个按钮上都增加了点击指定按钮的方式
【问题讨论】:
-
如您所见,您的问题没有得到很好的答案。原因之一是您无法轻松地帮助您。你的代码没有运行!我们尝试通过运行代码并查看输出和错误消息来查找代码中的问题。如果您不提供运行的代码,我们将不得不猜测它应该如何工作,我们可能是错误的。您没有提供样本数据。您使用
cur.fetchall()检索数据,但我们不知道该数据是什么样的。再次,我们将不得不猜测。如果您为我们提供这些东西会更容易。 -
@figbeam 谢谢我分享了所有代码,请尝试并再次帮助我如何从数据库中获取价格并将其乘以按钮点击次数
-
你有几个从数据库读取的函数。请交换数据库读取示例数据。我没有你的数据库。
-
@figbeam 我有三张早餐、午餐和晚餐的桌子,所以所有几个功能都从这三张桌子上读取我将这些名称读取为按钮,但我不想读取按钮中的价格我只是想要制作字典,然后使用 use 来乘以文本框中的按钮点击次数
-
@figbeam 请提供任何帮助或建议