您好,我正在制作一个以mysql为后端的python tkinter程序,并且我计划进行此程序的开发,在其中要键入预定总线的详细信息,并且必须在sql数据库中沿着总线号进行验证但是我遇到了问题,该程序无法提供所需的输出
我搜索了网和手册,但没有希望
import tkinter as tk
from tkinter import messagebox
import os
from mysql.connector import Error
def payment():
os.system('payment.py')
def chk1():
no = E5.get()
chk2(no)
def chk2(a):
import mysql.connector
try:
dbcrd = 'db.WDC'
with open(dbcrd) as f:
data = f.readlines()
uname = data[0].rstrip()
pword = data[1].rstrip()
lchst = data[2].rstrip()
mySQLConnection = mysql.connector.connect(host = lchst,user = uname,passwd = pword,database = 'booking',raw = True)
cursor = mySQLConnection.cursor()
sql_select_query = """select COUNT(*) from bus where B_No = %s"""
a = cursor.execute(sql_select_query,(a,))
exn1 = cursor.fetchall()
print (a)
for i in exn1:
print(i)
if exn1 != 1:
messagebox.showinfo('Error','The Given Bus number was not found')
else:
payment()
#c = cursor.fetchone()
#print (c)
except Error as e :
print (e)
global E5
D1=tk.Tk()
D1.geometry('350x200')
L1 = tk.Label(D1,text='Enter Passenger Name:')
E1 = tk.Entry(D1)
L2 = tk.Label(D1,text='Enter Gender')
E2 = tk.Entry(D1)
L3 = tk.Label(D1,text='Number of seats')
E3 = tk.Entry(D1)
L4 = tk.Label(D1,text='Date:')
E4 = tk.Entry(D1)
L5 = tk.Label(D1,text='Bus Number')
E5 = tk.Entry(D1)
L6 = tk.Label(D1,text='Phone Number:')
E6 = tk.Entry(D1)
L7 = tk.Label(D1,text='Aadhar')
E7 = tk.Entry(D1)
L1.grid(column = 1,row= 1)
L2.grid(column = 1,row= 2)
L3.grid(column = 1,row= 3)
L4.grid(column = 1,row= 4)
L5.grid(column = 1,row= 5)
L6.grid(column= 1,row= 6)
L7.grid(column= 1,row= 7)
E1.grid(column = 2,row= 1)
E2.grid(column = 2,row= 2)
E3.grid(column = 2,row= 3)
E4.grid(column = 2,row= 4)
E5.grid(column = 2,row= 5)
E6.grid(column = 2,row= 6)
E7.grid(column = 2,row= 7)
B2=tk.Button(D1,text='Next',width=12,height=1,command =chk1)
B2.grid(column=2,row=8 )
D1.mainloop()
错误是它没有运行定义付款,而是说没有找到总线号,尽管sql中的数据是正确的 我希望程序能够完美运行,并提供定义付款作为程序输出的结果