简体   繁体   English

我在 python 中创建了一个收据生成器,并将数据从 MySQL 提取到文本区域,但它不起作用。 我不知道我在哪里犯了错误

[英]I creating a receipt generator in python and I fetch data from MySQL to a text area but it's not work. I don't know that where I making the mistake

from tkinter import*

from PIL import Image,ImageTk

from tkinter import ttk

import mysql.connector

from tkinter import messagebox

import time

root=Tk()

root.title("Hotel Management System")

root.geometry("1135x470+225+221")

#====================== Variables ======================
        
var_id=StringVar()

#=====================Function for receipt and Fetch data from mysql ========================

def receipt():


 if var_id.get()=="":

  messagebox.showerror("Error","Please Enter Customer ID",parent=root)

 else:

  conn=mysql.connector.connect(host="localhost",username="root",password="sqlab12",database="management")

  my_cursor=conn.cursor()

  query=("select Ref from customer where Idnumber=%s")

  value=(var_id.get(),)

  my_cursor.execute(query,value)

  row=my_cursor.fetchone()



 if row==None:

  messagebox.showerror("Error","This Number is Not Found",parent=root)

 else:

  conn.commit()

  conn.close()

  date=time.strftime("%d/%m/%Y")

  textarea.insert(END,"Customer Ref:"+row+date)

    


#====================== Title =======================
 
lbl_title=Label(root,text="BILL GENERATE ",font=("time new 
roman",18,"bold"),bg="black",fg="gold",bd=4,relief=RIDGE)

lbl_title.place(x=0,y=0,width=1135,height=50)

#========================== LOGO =====================

img2=Image.open(r"F:\Pictures\VA\Project\Hotel Management System\images\logohotel.png")

img2=img2.resize((100,40),Image.ANTIALIAS)

photoimg2=ImageTk.PhotoImage(img2)

lblimg=Label(root,image=photoimg2,bd=0,relief=RIDGE)

lblimg.place(x=5,y=5,width=100,height=40)

#============================================== RECEIPT =================

F2=Frame(root,relief=GROOVE,bd=5)

F2.place(x=580,y=90,width=530,height=380)

bill_title=Label(root,text="Receipt",font=("arial",15,"bold"),bd=7,relief=GROOVE)

bill_title.place(x=580,y=50,width=530)

scrol=Scrollbar(F2,orient=VERTICAL)      

scrol.pack(side=RIGHT,fill=Y)

textarea=Text(F2,font=("arial",12,"bold"),yscrollcommand=scrol.set) 

textarea.pack(fill=BOTH)

scrol.config(command=textarea.yview)


#============================================== BUTTONS ============================

btn_frame=Frame(root,bd=3,relief=RIDGE)

btn_frame.place(x=6,y=346,width=417,height=42)


#=====================CUSTOMER_ID_NUMBER=================

lbl_cust_id=Label(root,text="Customer ID :",font=("arial",13,"bold"),padx=5,pady=4)

lbl_cust_id.place(x=6,y=250)

enty_id=ttk.Entry(root,width=23,textvariable=var_id,font=("arial",13,"bold"))

enty_id.place(x=140,y=250)

btnReceipt=Button(btn_frame,text="Receipt",command=receipt,font=("arial",11,"bold"),bg="black",fg="gold",width=10)

btnReceipt.grid(row=0,column=0,padx=2,pady=2)

btnPrint=Button(btn_frame,text="Print",font=("arial",11,"bold"),bg="black",fg="gold",width=10)

btnPrint.grid(row=0,column=1,padx=1,pady=2)

btnSave=Button(btn_frame,text="Save",font=("arial",11,"bold"),bg="black",fg="gold",width=10)

btnSave.grid(row=0,column=2,padx=1,pady=2)

btnSend=Button(btn_frame,text="Send",font=("arial",11,"bold"),bg="black",fg="gold",width=10)

btnSend.grid(row=0,column=3,padx=1,pady=2)



root.mainloop()

You are missing something to insert in place of the %s:您缺少要插入的内容来代替 %s:

query=("select Ref from customer where Idnumber=%s")

needs to have something like需要有类似的东西

query=("select Ref from customer where Idnumber=%s" % Idnumber)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在创建密码生成器,但我不知道为什么它不起作用 - I'm creating a password generator but I don't know why it doesn't work 我不知道为什么我的 delete 和 ping 不起作用。 Python - I don't know why my delete and ping wont work. Python 我找到了错误的原因,但我不知道如何解决 - I found the reason for the mistake but I don't know how to solve it 我不知道如何使用 Python 将传感器数据从树莓派发送到 MySQL 服务器 - I don't know how to send sensor data from a Raspberry Pie to MySQL Server with Python 我在python中的返回字符串后面有一个空格,我不知道如何摆脱或它来自哪里 - I have a space after a return string in python that I don't know how to get rid of or where it's coming from Python:我不明白这个生成器发生了什么 - Python: I don't understand what's happening with this generator 在 python 中,当我不知道不需要的数据将在哪里弹出或特定字符串是什么时,从数据列表中删除不需要的项目? - In python remove unwanted item from a list of data when I don't know where the unwanted data will pop up, or what the specific string will be? item函数中的each_item不起作用。 我不知道如何实现nested_item - A each_item in item function doesn't work. I don't know how to implement nested_item 我在哪里用这个装饰器代码犯了错误? - Where I am making a mistake with this decorator code? 我不明白的 Python 代码或 CNN 架构功能的错误 - Mistake on Python code or CNN architecture feature that I don't understad
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM