我的项目是创建一个emenu。为此我在phpmyadmin中创建了一个数据库。使用下面的代码访问了菜单。现在我想将该菜单项发送到一个新的数据库(已经创建) )点击“添加到购物车”按钮。我似乎无法找到一种方法将值作为变量传递。在此代码中的价格。这是我的代码:
class Appetizers(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
self.controller=controller
def insdb():
cro=mysql.connector.connect(user='k***',password='***',host='******',database='newdb')
mycursor=cro.cursor()
mycursor.execute("""INSERT INTO order_frm_client(name,quantity,price) VALUES(name,2,price)""" )
cro.commit()
conn=mysql.connector.connect(user='k***',password='***',host='*****',database='menu')
mycursor=conn.cursor()
mycursor.execute("SELECT * FROM APPETIZERS")
results=mycursor.fetchall()
yo=50
for row in results:
id=row[0]
name=row[1]
price=row[3]
listBox = Listbox(self, height=1,width=40,highlightcolor="red")
listBox.place(x=100,y=yo)
listBox.insert(END,name)
listBox1 = Listbox(self, height=1,width=10,highlightcolor="red")
listBox1.place(x=350,y=yo)
listBox1.insert(END,price)
spin=Spinbox(self, from_=0, to=10, width=10).place(x=420,y=yo)
button=Button(self, text='Add to Cart',width=4, command=insdb(name,price))
button.place(x=500,y=yo)
yo=yo+30