NameError:名称“ insert_sql”未定义

时间:2019-11-24 10:35:24

标签: python-3.x tkinter

这是Bank.py文件:

from customer_dbScript import *
from tkinter import *
from tkinter import messagebox

window = Tk()
window.geometry("300x420+30+30")
window.resizable(0,0)
window.title("Bank of Tkinter")


def put():
    # accessing values from UI
    name = txt_name.get()
    dob = txt_dob.get()
    phno = txt_phno.get()
    email = txt_email.get()
    adhar = txt_adhar.get()
    pan = txt_pan.get()
    city = txt_city.get()
    user = txt_user.get()
    pwd = txt_pass.get()
    bal = txt_bal.get()

    data = (
        name, dob, phno, email, adhar, pan, city, user, pwd, bal
    )

    res = insert_sql(data)

    if res:
        # root.destroy()
        # menu()
        messagebox.showinfo("Alert!", "worked")
    else:
        messagebox.showinfo("Alert!", "Wrong username/password")


# Button
btn_submit = Button(window, text="Register", command=put)
btn_submit.place(x=100, y=370)

window.mainloop()

这是customer_dbScript.py文件

from Bank import *
import mysql.connector
from tkinter import messagebox

mydb = mysql.connector.connect(
    host="localhost",
    user="root",
    db="python_db"
)

mycursor = mydb.cursor()

# inserting into table
def insert_sql(tup):
    # insert query
    sql_insert = "INSERT INTO customer (name, dob, ph_no, email, adhar, PAN, city, username, password, balance)" \
                 "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
    mycursor.execute(sql_insert, tup)
    mydb.commit()
    messagebox.showinfo("Message", f"{mycursor.rowcount} record(s) inserted")
    return True

当我单击“提交”按钮时,出现以下错误:

  

第88行的文件“ D:\ Python Spark \ TkinterDemo \ Bank.py”       res = insert_sql(数据)

     

NameError:名称'insert_sql'未定义

0 个答案:

没有答案