我又遇到麻烦了。
有人能帮我吗?当我想从Tkinter Entry(Widgets)向数据库中放入一些数据时,我遇到了问题。
我的数据库中有表“book”,我想将tkinter中的一些数据放入表“book”。
我已经使用了get,但我的程序中没有任何内容
有人能帮我吗?在
谢谢。哦,是的,这是我的剧本:)from tkinter import *
import mysql.connector as mc
import tkinter.messagebox as tm
def put(*args):
e_code = i_code.get()
e_name = i_name.get()
e_price = i_price.get()
conn = mc.connect(user="root", password="mypassword", host="localhost", database="book_test")
cur = conn.cursor()
cur.execute("insert into book(book_code, book_name, book_price) values('"+e_code+"', '"+e_name+"', '"+e_price+"')")
conn.close()
root = Tk()
root.title("GET DATA")
mainframe = Frame(root)
mainframe.pack()
i_code = IntVar()
i_name = StringVar()
i_price = IntVar()
codeEntry = Entry(mainframe, width=7, textvariable=i_code)
nameEntry = Entry(mainframe, width=7, textvariable=i_name)
priceEntry = Entry(mainframe, width=7, textvariable=i_price)
codeEntry.grid(row=0, column=1)
nameEntry.grid(row=1, column=1)
priceEntry.grid(row=2, column=1)
Label(mainframe, text='Book Code').grid(row=0, column=0)
Label(mainframe, text='Book Name').grid(row=1, column=0)
Label(mainframe, text='Book Price').grid(row=2, column=0)
Button(mainframe, text="Insert", command=put).grid(row=3, column=1)
root.mainloop()
我犯了这个错误,有人能帮我吗?或者给我线索哈哈哈。在
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 1553, in __call__return self.func(*args)
File "/home/oncom/PycharmProjects/guiProject/fkinggetdata.py", line 13, in put
cur.execute("insert into book(book_code, book_name, book_price) values('"+e_code+"', '"+e_name+"', '"+e_price+"')")
TypeError: Can't convert 'int' object to str implicitly