【发布时间】:2021-12-24 03:28:06
【问题描述】:
##GUI FILE
root = Tk()
root.title("Inventory Management")
root.geometry('1000x600')
def add_inventory():
myInventory = product.Product()
myInventory.setProductID(productID.get())
myInventory.setProdName(productName.get())
myInventory.addProduct()
productID = IntVar()
productName = StringVar()
prodIDentry = Entry(productframe, width=22, textvariable=productID)
prodNameentry = Entry(productframe, width=22, textvariable=productName)
btn_add = Button(productframe, text="Add", font="Verdana 10 bold", command = add_inventory)
##product file
class Product:
def __init__(self):
self.ProductID = ''
self.ProdName = ''
prodID = self.getProductID()
prodname = self.getProdName()
def getProductID(self):
return self.ProductID
def setProductID(self, value):
self.ProductID = value
def getProdName(self):
return self.getProdName
def setProdName(self, value):
self.ProdName = value
def addProduct(self):
mydb = mysql.connector.connect(
host='localhost',
database='PHP',
user='root',
password=''
)
mycursor = mydb.cursor()
sql1 = "INSERT INTO product (ProductID, ProdName) VALUES (%s,%s)"
val = (prodID, prodname)
mycursor.execute(sql1, val)
mydb.commit()
我的程序有一个需要用户输入的 GUI,然后它会通过单击按钮将输入输入数据库。这些是我要插入的几个变量。 但是一直返回:_mysql_connector.MySQLInterfaceError: Python类型方法无法转换
【问题讨论】:
-
如果您在执行前
print(val)会发生什么? -
@AKX 嗨,对不起,我刚刚在我的问题中添加了更多代码,请看一下:/我需要帮助
-
你的代码没有意义。一方面,类主体中现在有 MySQL 代码,在任何函数之外?代码中的任何地方也没有
getProductID()函数。 -
@AKX 我刚刚又编辑了一次,很抱歉我不太熟悉如何显示问题...现在你理解更好了吗?
-
对不起,没有。如果您有一个调用
self.getProductID()函数的有问题的段,您还应该在帖子中包含该函数。
标签: python mysql mysql-python